/* Для специального JS-кода конкретных пректов */

function Get_rider()
{
$("#rider_result_info").removeClass('success').removeClass('error').addClass('show').html('Подождите, идет обработка...');

jQuery.ajax({
		type: "post",
		dataType: "json",
		data: "script=rider&rider_key="+$("#rider_key").val(),
		url: "/ajax/",
		success: function(data, textStatus)
		{			
			$("#rider_key").val('');
			if(data.error == 0)
			{
				$("#rider_result_info").removeClass('error').addClass('success').addClass('show').html('Ссылка на скачивание файла: <a href="'+data.link+'">Скачать</a>');
			}
			else
			{
				$("#rider_result_info").removeClass('success').addClass('error').addClass('show').html('Вы ввели неверный код!');
			}
		},
		error: function()
		{
			
		}
	});
}

function DecorateMenu()
{
	$("#header_menu div.menu_item:first-child div.menu_text a").addClass("first_child");
	$("#header_menu div.menu_item:last-child div.menu_text a").addClass("last_child");
	$("#header_menu div.delimiter:last-child").css("display", "none");

	$("#footer_menu div.menu_item:first-child").addClass("first_child");
	$("#footer_menu div.menu_item:last-child").addClass("last_child");
}

function IE6Fix()
{
	if(jQuery.browser.msie && jQuery.browser.version.substr(0,1) == "6")
	{
		$("#header_menu div.menu_item div.menu_text a").each(function(){
			$(this).css("display", "inline");
			$(this).css("width", $(this).width() + "px");
			$(this).css("display", "block");
		});

		$("#header_search_button").attr("src", "/img/header_search/search_button.gif");
	}
}

function DecoratePhotos()
{
	$("#wrapper_td img[class!=not_photo]").wrap("<div class='content_photo' />");


	$("div.content_photo").each(function(){
		if($(this).children("img").hasClass("float_left"))
		{
			$(this).addClass("float_left");
			$(this).children("img").removeClass("float_left");
			$(this).css("margin-right", "10px");
			$(this).css("text-align", "center");
		}
		if($(this).children("img").attr("title") != "")
		{
			$(this).children("img").after("<div class='content_photo_description' />");
			$(this).children("div.content_photo_description").html($(this).children("img").attr("title"));
		}
	});

	$("div.content_photo > img.not_photo").unwrap();
}

function DecorateDocuments()
{
	$("#wrapper_td a.document_doc").wrap("<div class='document_doc' />");
	$("#wrapper_td a.document_xls").wrap("<div class='document_xls' />");
	$("#wrapper_td a.document_pdf").wrap("<div class='document_pdf' />");
	$("#wrapper_td a.document_rar").wrap("<div class='document_rar' />");

	$("#wrapper_td div.document_doc, #wrapper_td div.document_xls, #wrapper_td div.document_pdf, #wrapper_td div.document_rar").each(function(){
		$(this).html($(this).children("a").html() + "&nbsp;&nbsp;<a href='" + $(this).children("a").attr("href") + "'>Скачать</a>");
	});
}

function EmbedPlayer()
{
	swfobject.embedSWF("/players/play.swf", "header_player_object", 181, 41, "9.0.115.0", "/players/expressInstall.swf",
	{
		wmode: "transparent"

	},
	{
		wmode: "transparent" //,
		/*allowScriptAccess: "always"*/
	}
	);
}

function PhotoGalleryInitialize()
{
	var size = $("a img.photo").size();
	if(0 <= size && size <= 1)
	{
		$("div.big_photo_arrow").hide();
	}
	else if(size > 1)
	{
		$("div.photo_larr").hide();
	}

	$("div.big_photo_div img.big_photo").attr("src", $("img.photo:first-child").attr("rel"));

	$("a img.photo").click(function(){
		$("a img.photo").removeClass("active");
		$(this).addClass("active");
		$("div.big_photo_div img.big_photo").attr("src", $(this).attr("rel"));
		if($(this).hasClass("first"))
		{
			$("div.photo_larr").hide();
			$("div.photo_rarr").show();
		}
		else if($(this).hasClass("last"))
		{
			$("div.photo_larr").show();
			$("div.photo_rarr").hide();
		}
		else
		{
			$("div.big_photo_arrow").show();
		}
		return false;
	});
	
	$("div.photo_larr a").click(function(){
		$("a img.active").removeClass("active").parent().parent().prev().children("div").children("img").addClass("active");
		$("div.big_photo_div img.big_photo").attr("src", $("a img.active").attr("rel"));
		if($("a img.active").hasClass("first"))
		{
			$("div.photo_larr").hide();
		}
		$("div.photo_rarr").show();
		return false;
	});
	
	$("div.photo_rarr a").click(function(){
		$("a img.active").removeClass("active").parent().parent().next().children("div").children("img").addClass("active");
		$("div.big_photo_div img.big_photo").attr("src", $("a img.active").attr("rel"));
		if($("a img.active").hasClass("last"))
		{
			$("div.photo_rarr").hide();
		}
		$("div.photo_larr").show();
		return false;
	});
}

function InitializeAnimation()
{
	swfobject.embedSWF("/swf/logo.swf", "header_logo_inner", 322, 110, "9.0.115.0", "",
	{
		wmode: "transparent"
	},
	{
		wmode: "transparent"
	});
	swfobject.embedSWF("/swf/Koncert.swf", "header_concert_inner", 141, 116, "9.0.115.0", "",
	{
		wmode: "transparent"
	},
	{
		wmode: "transparent"
	});
}

$(document).ready(function(){
	InitializeAnimation();
	DecorateMenu();
	IE6Fix();
	DecoratePhotos();
	DecorateDocuments()

	$("#footer_menu div.menu_item").unbind("mouseenter");
	$("#footer_menu div.menu_item").unbind("mouseleave");
	
	PhotoGalleryInitialize();
	
	EmbedPlayer();
	
	$("a.print").click(function(){
		window.print();
		return false;
	});
	
	$("#rider_key_submit").click(function(){
		Get_rider();
		return false;
	});
	$("#get_rider").submit(function(){
		Get_rider();
		return false;
	});
});
