$(document).ready(function() 
{

var userAgent = navigator.userAgent.toLowerCase();
jQuery.browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1],
	chrome: /chrome/.test( userAgent ),
	safari: /webkit/.test( userAgent ) && !/chrome/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};



	$.h1_height = $('h1').height();
	$.random_height = $('#randomsongdyn').height();
	if($.h1_height > 0)
	{
		if ($.browser.msie && $.browser.version==7)
		{
    	$.sumatory = 0;
    }
    else
    {
    	$.sumatory = 20;
    }
		$.random_margin = $.h1_height - $.random_height + $.sumatory;
	}
	else
	{
		$.random_margin = 20;
	}
	$("#randomsongdyn").css('margin-top', $.random_margin + "px").fadeIn('normal');
	

	$.search_default = 'Lady Gaga - Just Dance';
	$('#search_input_en, #search_input_es').click(function(){
		if($(this).val())
		{
			$.search_default = $(this).val();
		}
		$(this).val('');
	});
	
	$('#search_input_en, #search_input_es').bind('blur', function(){
		if($(this).val() == '')
		{
			$(this).val($.search_default);
		}
	});

	$.fn.qtip.styles.search = {
  	width: 320,
    height: 120,
    padding: 0,
  	background: '#073137',
  	color: '#FFFFFF',
  	textAlign: 'center',
  	border: {
      width: 7,
      radius: 0,
      color: '#073137'
  	},
  	tip: 'topLeft',
   	name: 'dark'
	}
	
	$.fn.qtip.styles.search2 = {
  	width: 320,
    height: 120,
    padding: 0,
  	background: '#073137',
  	color: '#FFFFFF',
  	textAlign: 'center',
  	border: {
      width: 7,
      radius: 0,
      color: '#073137'
  	},
  	tip: 'rightMiddle',
   	name: 'dark'
	}
	
	$.fn.qtip.styles.social = {
  	width: 250,
    height: 30,
    padding: 0,
  	background: '#073137',
  	color: '#FFFFFF',
  	textAlign: 'center',
  	border: {
      width: 7,
      radius: 0,
      color: '#073137'
  	},
  	tip: 'topMiddle',
   	name: 'dark'
	}

	$.fn.qtip.styles.originalsong = {
  	width: 442,
    height: 264,
    padding: 0,
  	background: '#073137',
  	color: '#FFFFFF',
  	textAlign: 'center',
  	border: {
      width: 7,
      radius: 0,
      color: '#073137'
  	},
  	tip: 'topMiddle',
   	name: 'dark'
	}

	$.fn.qtip.styles.footerbuttons = {
  	width: 300,
    height: 200,
    padding: 0,
  	background: '#073137',
  	color: '#FFFFFF',
  	textAlign: 'center',
  	border: {
      width: 7,
      radius: 0,
      color: '#073137'
  	},
  	tip: 'topMiddle',
   	name: 'dark'
	}
	
	$.fn.qtip.styles.footerbuttons2 = {
  	width: 400,
    height: 180,
    padding: 0,
  	background: '#073137',
  	color: '#FFFFFF',
  	textAlign: 'center',
  	border: {
      width: 7,
      radius: 0,
      color: '#073137'
  	},
  	tip: 'topMiddle',
   	name: 'dark'
	}
	
	$.fn.qtip.styles.idioma_es = {
  	width: 300,
    height: 30,
    padding: 0,
  	background: '#073137',
  	color: '#FFFFFF',
  	textAlign: 'center',
  	border: {
      width: 7,
      radius: 0,
      color: '#073137'
  	},
  	tip: 'bottomMiddle',
   	name: 'dark'
	}
	
	$.fn.qtip.styles.idioma_en = {
  	width: 300,
    height: 30,
    padding: 0,
  	background: '#073137',
  	color: '#FFFFFF',
  	textAlign: 'center',
  	border: {
      width: 7,
      radius: 0,
      color: '#073137'
  	},
  	tip: 'bottomMiddle',
   	name: 'dark'
	}

	$("#contact_es").qtip({
  	content: '<img src="http://www.cantanding.com/templates/default/img/logo-bocadillos.png" /><br />&iquest;tienes alguna duda, sugerencia o queja? <br />&iquest;Quieres decirnos algo?<br />&iexcl;escr&iacute;benos a cantanding@gmail.com y te contestaremos lo antes posible!',
  	position: {
      corner: {
         target: 'bottomMiddle',
         tooltip: 'topMiddle'
      }
    },
    show: {
      when: 'click', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'footerbuttons' 
	});
	
	$("#contact_en").qtip({
  	content: '<img src="http://www.cantanding.com/templates/default/img/logo-bocadillos.png" /><br />Any doubt, suggestion or complaint?<br/>Do you want to tell us anything?<br/>Write us to cantanding@gmail.com and we\'ll reply as soon as possible!',
  	position: {
      corner: {
         target: 'bottomMiddle',
         tooltip: 'topMiddle'
      }
    },
    show: {
      when: 'click', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'footerbuttons' 
	});
	
	$("#credits_es").qtip({
  	content: '<img src="http://www.cantanding.com/templates/default/img/logo-bocadillos.png" /><br />cantanding es una idea original de <a href="http://www.twitter.com/danielperis" target="_blank">@danielperis</a> y <a href="http://soundcloud.com/butter-cannons" target="_blank">DiscoInferno</a><br/>Desarrollada por <a href="http://www.twitter.com/danielperis" target="_blank">@danielperis</a> y <a href="http://www.grindcode.com" target="_blank">grindcode</a><br/>El servidor ha sido cedido por nuestro SysAdmin favorito: <a href="http://www.leopoldomaestro.com" target="_blank">LeoMaestro</a>.',
  	position: {
      corner: {
         target: 'bottomMiddle',
         tooltip: 'topMiddle'
      }
    },
    show: {
      when: 'click', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'footerbuttons2' 
	});
	
	$("#credits_en").qtip({
  	content: '<img src="http://www.cantanding.com/templates/default/img/logo-bocadillos.png" /><br />cantanding is an original idea by <a href="http://www.twitter.com/danielperis" target="_blank">@danielperis</a> & <a href="http://soundcloud.com/butter-cannons" target="_blank">DiscoInferno</a><br/>Developed by <a href="http://www.twitter.com/danielperis" target="_blank">@danielperis</a> & <a href="http://www.grindcode.com" target="_blank">grindcode</a><br/>Server stuff by our favourite SysAdmin: <a href="http://www.leopoldomaestro.com" target="_blank">LeoMaestro</a>.',
  	position: {
      corner: {
         target: 'bottomMiddle',
         tooltip: 'topMiddle'
      }
    },
    show: {
      when: 'click', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'footerbuttons2' 
	});
	
	$("#search_input_es").qtip({
  	content: 'Introduce el nombre del artista y el t&iacute;tulo de la canci&oacute;n que quieras cantar de esta forma: <br/>ARTISTA - CANCI&Oacute;N.<br/>Ejemplo: Michael Jackson - Beat it',
  	position: {
      corner: {
         target: 'bottomRight',
         tooltip: 'topMiddle'
      }
    },
    show: {
      when: 'click', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'search' 
	});
	
	$("#search_input_en").qtip({
  	content: 'Enter the artist\'s name and the title of the song you want to sing in this way: <br/>ARTIST - SONG. <br/>Example: Michael Jackson - Beat it',
  	position: {
      corner: {
         target: 'bottomRight',
         tooltip: 'topMiddle'
      }
    },
    show: {
      when: 'click', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'search' 
	});
	
	$("#search_input_ex_es").qtip({
  	content: 'Introduce el nombre del artista y el t&iacute;tulo de la canci&oacute;n que quieras cantar de esta forma: <br/>ARTISTA - CANCI&Oacute;N.<br/>Ejemplo: Michael Jackson - Beat it',
  	position: {
      corner: {
         target: 'leftMiddle',
         tooltip: 'rightMiddle'
      }
    },
    show: {
      when: 'click', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'search2' 
	});
	
	$("#search_input_ex_en").qtip({
  	content: 'Enter the artist\'s name and the title of the song you want to sing in this way: <br/>ARTIST - SONG. <br/>Example: Michael Jackson - Beat it',
  	position: {
      corner: {
         target: 'leftMiddle',
         tooltip: 'rightMiddle'
      }
    },
    show: {
      when: 'click', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'search2' 
	});
	
	$("#flag_en_es").qtip({
  	content: 'cantanding en ingl&eacute;s',
  	position: {
      corner: {
         target: 'topMiddle',
         tooltip: 'bottomMiddle'
      }
    },
    show: {
      when: 'mouseover', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'idioma_en' 
	});
	$("#flag_en_en").qtip({
  	content: 'cantanding in english',
  	position: {
      corner: {
         target: 'topMiddle',
         tooltip: 'bottomMiddle'
      }
    },
    show: {
      when: 'mouseover', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'idioma_en' 
	});
	$("#flag_es_es").qtip({
  	content: 'cantanding en espa&ntilde;ol',
  	position: {
      corner: {
         target: 'topMiddle',
         tooltip: 'bottomMiddle'
      }
    },
    show: {
      when: 'mouseover', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'idioma_es' 
	});
	$("#flag_es_en").qtip({
  	content: 'cantanding in spanish',
  	position: {
      corner: {
         target: 'topMiddle',
         tooltip: 'bottomMiddle'
      }
    },
    show: {
      when: 'mouseover', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'idioma_es' 
	});
	
	
	$("#social_twitter_en").qtip({
  	content: 'Share on Twitter',
  	position: {
      corner: {
         target: 'bottomMiddle',
         tooltip: 'topMiddle'
      }
    },
    show: {
      when: 'mouseover', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'social' 
	});
	
	$("#social_twitter_es").qtip({
  	content: 'Compartir en Twitter',
  	position: {
      corner: {
         target: 'bottomMiddle',
         tooltip: 'topMiddle'
      }
    },
    show: {
      when: 'mouseover', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'social' 
	});
	
	$("#social_myspace_en").qtip({
  	content: 'Share on MySpace',
  	position: {
      corner: {
         target: 'bottomMiddle',
         tooltip: 'topMiddle'
      }
    },
    show: {
      when: 'mouseover', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'social' 
	});
	
	$("#social_myspace_es").qtip({
  	content: 'Compartir en MySpace',
  	position: {
      corner: {
         target: 'bottomMiddle',
         tooltip: 'topMiddle'
      }
    },
    show: {
      when: 'mouseover', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'social' 
	});
	
	$("#social_facebook_en").qtip({
  	content: 'Share on Facebook',
  	position: {
      corner: {
         target: 'bottomMiddle',
         tooltip: 'topMiddle'
      }
    },
    show: {
      when: 'mouseover', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'social' 
	});
	
	$("#social_facebook_es").qtip({
  	content: 'Compartir en Facebook',
  	position: {
      corner: {
         target: 'bottomMiddle',
         tooltip: 'topMiddle'
      }
    },
    show: {
      when: 'mouseover', 
        solo: true 
      },
      hide: 'unfocus', 
  	style: 'social' 
	});
   
    $("#orsong").qtip(
    {
      content: '<div id="youtube-embed-'+$('#orsong').attr('rel')+'">You need Flash player 8+ to view this video.</div>',
      position: {
         corner: {
           tooltip: 'topMiddle', 
           target: 'bottomMiddle' 
         }
      },
      show: {
      	when: 'click',
        	solo: true
        },
        hide: 'unfocus', 
        style: 'originalsong',
        api: {
        	onRender: function()
          {
          	//var original = $('#video object');
            //original.pauseVideo();

            $('#youtube-embed-'+$('#orsong').attr('rel')+'').html('<object width="432" height="264"><param name="movie" value="http://www.youtube.com/v/'+$('#orsong').attr('rel')+'&hl=es_ES&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+$('#orsong').attr('rel')+'&hl=es_ES&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="432" height="264"></embed></object>');
            
          },

          onHide: function(){
            var playerAPI = this.elements.content.find('#youtube-video-'+$(this).attr('rel')).get(0);
            if(playerAPI && playerAPI.pauseVideo) playerAPI.pauseVideo();
          }
        }
      }
    );
});
