$(function()
{
	$("html").addClass("js");

	var page = $("body").attr("rel");
	
	// begin AUDIO PLAYER
	var flashvars = {
		"playlist" : "/xml/playlist.mpl",
		"auto_run" : "0",
		"repeat" : "1",
		"shuffle" : "0",
		"anti_cache" : "0",
		"unicode" : "1",
		"l":"FFFFFF", "m":"7F807E", "d":"7F807E", "b":"7F807E", "p":"FFFFFF", "tt":"FFFFFF","tbd":"7F807E", "tbm":"FFFFFF", "tbl":"FF2F86",	"lvd":"7F807E",
		"lvl":"FFFFFF"
	};
	var params = {"loop":"false", "menu":"false","quality":"high","wmode":"transparent","bgcolor":"#000000","swliveconnect":"true","allowscriptaccess":"sameDomain"};
	var attributes = {"name":"mju","id":"mju"};
	swfobject.embedSWF("/swf/mju.swf", "player", "150", "150", "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);

	var opera = Boolean(window["opera"]);
	var ie = (navigator.appName.indexOf("Microsoft") != -1) && !opera;	
	function mju_play_file(chars) {
		if (!chars.length) return false;
		var mc = ie ? window.mju : window.document.mju;
		mc.SetVariable("play_file",chars);
	}
	function mju_play_track(num) {
		if (num <= 0) return false;
		var mc = ie ? window.mju : window.document.mju;
		mc.SetVariable("play_track",num);
	}
	function mju_do(cmd) {
		if (!cmd.length) return false;
		var mc = ie ? window.mju : window.document.mju;
		mc.SetVariable("do_"+cmd," ");
	}
	// end AUDIO PLAYER

	

	if (page == 'main')
	{
		$('ul.news li:first').addClass('first');
		$('ul.news li:last').addClass('last');	
	}
	else if (page == 'video' || page == 'photo')
	{
		var w_height =$(window).height();
		if (w_height > 895)
		{
			$('.scroll-pane').css('height', (w_height - 423)+'px');
		}
		$('.scroll-pane').jScrollPane({scrollbarWidth:9, dragMaxHeight:41});
		
		if (page == 'photo')
		{
			$("a[rel='colorbox']").colorbox({slideshow:true, transition: "fade", speed: 200,slideshowAuto: false});
			$('#colorbox').append($('#socials_share'));
			/*
			$("#photos a").click(function(){
				window.location.hash = $(this).data('hash');
				$.colorbox({href:$(this).attr('rel'), iframe:true, innerWidth:700, innerHeight:600,
					onClosed:function(){
						window.location.hash = '';
					}
				});	
				return false;
			});
			
			// open photo by hash
			//alert(location.hash.substring(6));
			if (window.location.hash != '' && location.hash.substring(1, 6) == 'photo' && parseInt(location.hash.substring(6)) >= 0)
			{
				num = location.hash.substring(6);
				
				
				var hash = location.hash.substring(1);
				obj_news_categories_li.removeClass('active');
				obj_news_categories_li.find('a[rel='+url+']').parent().addClass('active').find('div').show();
				$.get('/news/load.news/', { 'url': url }, loadNews);

			}
			*/
		}
	}//else if (page == 'video' || page == 'photo')
	else if (page == 'contacts')
	{
		//$(".left_content ul").find('li:last').addClass('last');
		//.contacts .left_content ul
		$(".left_content ul li p a").hover(
			function(){
				$(this).parent().parent().find('a.circle').addClass('hover');
			},
			function(){
				$(this).parent().parent().find('a.circle').removeClass('hover');
			}
		);
		$(".left_content ul li a.circle").hover(
			function(){
				$(this).parent().find('a').css({color:"#ff2e87"});
			},
			function(){
				$(this).parent().find('a').css({color:""});
			}
		);
			
		// begin FEEDBACK BLOCK
		if ($("#feedback").length)
		{
			$("#feedback").validate({
				submitHandler: function(form){
					$(form).ajaxSubmit({
						beforeSubmit: function(){
							$("#feedback_loading").show();
						},
						resetForm: true,
						success: function(data){
							$("#feedback_loading").hide();
							$("#feedback_msg").html(data).show();
						}
					});
				},
				rules : {
					name : "required",
					email: {
						email: true
					},
					message : "required"	
				},
				messages : {
					name : {
						required : "Введите ваше имя!"
					},
					
					email: {
						email: "Введите корректный адрес электронной почты!"
					},
					message : {
						required : "Введите сообщение!"
					}
				}
			});
		}
		// end FEEDBACK BLOCK
	}
	//else if (page == 'contacts')
	else if (page == 'about')
	{
		if ($("#team").length)
		{
			$("#team h4 a").hover(
				function(){
				$(this).parent().parent().find('a.circle').addClass('hover');
				},
				function(){
					$(this).parent().parent().find('a.circle').removeClass('hover');
				}
			);
			$("#team a.circle").hover(
				function(){
					$(this).parent().find('h4 a').css({color:"#ff2e87"});
				},
				function(){
					$(this).parent().find('h4 a').css({color:""});
				}
			);
		}
	}

	// begin SOCIAL BUTTONS
	$('#share_fb').click(function(){
		window.open(this.href, "facebook-share", 'width=600,height=400,top=100,left=100,toolbar=no,menubar=no');
		return false;
	});
	$('#share_vk').click(function(){
		window.open(this.href, "vkntakte-share", 'width=600,height=280,top=100,left=100,toolbar=no,menubar=no');
		return false;
	});
	$('#share_tw').click(function(){
		window.open(this.href, "vkntakte-share", 'width=600,height=400,top=100,left=100,toolbar=no,menubar=no');
		return false;
	});
	$('#share_gl').click(function(){
		window.open(this.href, "google-bookmark", 'width=512,height=450,top=100,left=100,toolbar=no,menubar=no');
		return false;
	});
	$('#share_ya').click(function(){
		window.open(this.href, "yandex-bookmark", 'width=885,height=569,top=100,left=100,toolbar=no,menubar=no,scrollbars=1');
		return false;
	});
	$('#share_my').click(function(){
		window.open(this.href, "myspace-post", 'width=885,height=402,top=100,left=100,toolbar=no,menubar=no,scrollbars=0');
		return false;
	});	
	// end SOCIAL BUTTONS
	
	
	// begin opacity
	$("#vote").hover(
		function() {
			$(this).stop().fadeTo('fast', 0.8)
		},
		function() {
			$(this).stop().fadeTo('fast', 1)
		}
	);
	// footer socials
	$("#socials").find('a').hover(
		function() {
			$(this).stop().fadeTo('fast', 0.6)
		},
		function() {
			$(this).stop().fadeTo('fast', 1)
		}
	);
	// end opacity
	
	
	/*-----------------------------------------------------------------------------------*/
	/*	tracklist 
	/*-----------------------------------------------------------------------------------*/	

	$("#tracklist div.lyrics").each(function(i)
	{
		$(this).parent('li:has(div.lyrics)').find('a').not('.button').addClass('collapsible').click(function()
		{
			var this_i = $('ol#tracklist .lyrics').index($(this).next());

			if ($(this).parent('li').find('.lyrics').css('display') == 'none')
			{
				// When opening one submenu, we hide all same level submenus:
				$(this).parent('li').parent('ol').find('.lyrics').each(function(j)
				{
					if (j != this_i)
					{
						$(this).slideUp(200, function()
						{
							$(this).parent('li').parent('ol').find('.collapsible').removeClass('opened').addClass('closed');
						});
					}
				});
				// :end
				$(this).parent('li').find('.lyrics').slideDown(200, function ()
				{
					// Show submenu:
					$(this).parent('li').find('.collapsible').removeClass('closed').addClass('opened');
				});
			}
			else
			{
				$(this).parent('li').find('.lyrics').slideUp(200, function()
				{
					// Hide submenu:
					$(this).parent('li').find('.collapsible').removeClass('opened').addClass('closed');			

					$(this).find('.lyrics').each(function()
					{
						$(this).hide(0);
					});
				});
			}
			return false;
		});

	});

	$("#tracklist a.button").toggle(
		function() {
			$("#tracklist a.button").removeClass('opened');
			$(this).addClass('opened');
			mju_do('pause');
			mju_play_file($(this).attr('rel'));
			return false;
		},
		function() {
			$(this).removeClass('opened');
			mju_do('pause');
			return false
		}
	);
});
