var ie6 = false;
var swfVersionStr = "8.0.24";
var xiSwfUrlStr = "";
var flashvars = {};
var attributes = {};
var params = {};
params.quality = "high";
params.bgcolor = "#ffffff";
params.play = "true";
params.loop = "true";
params.wmode = "transparent";
params.allowscriptaccess = "sameDomain";
params.menu = "false";
params.devicefont = "false";
params.scale = "noscale";

$(document).ready(
	function() {
		
		if (jQuery.browser.msie && jQuery.browser.version.indexOf("6.") != -1) ie6 = true;
		
		//SHOW USER PANEL END
		if ($("div.wrapper").width() >= 1375) {
			$("img.user_panel_end").show();
			$("img.menu_photo_end").show();
		}
		
		//AUTH FORM SHOW/HIDE
		$("div.enter_reg span").click (
			function () {
				$("div.auth").fadeIn("fast");
			}
		);
		$("img.auth_close").click (
			function () {
				$("div.auth").fadeOut("slow");
			}
		);
		
		//FEEDBACK FORM SHOW/HIDE
		var feedback_html = $("div.feedback").html();
		$("div.main_menu_bottom img").click (
			function () {
				$("div.feedback").css("left", $(this).position().left - 190 + "px").fadeIn("fast");
			}
		);
		$("img.feedback_close").live ("click",
			function () {
				$("div.feedback").fadeOut("slow",
					function () {
						$("div.feedback").html(feedback_html);
					}
				);
			}
		);
		
		//OTHER SERVICE SHOW/HIDE
		$("div.main_menu_bottom span").click (
			function () {
				$("div.main_menu_bottom small").html("&#9660;");
				$("div.other_service").css({"top":$("strong", this).position().top - 3 + "px","left":$("strong", this).position().left - 10 + "px"}).slideDown("fast");
				$("div.main_menu_bottom strong").css("border", "none");
			}
		);
		$("div.other_service").mouseleave (
			function () {
				$("div.main_menu_bottom small").html("&#9658;");
				$(this).slideUp("fast");
				$("div.main_menu_bottom strong").css("border-bottom", "1px dashed #FFF");
			}
		);
		
		//MY ALBUM LIST SHOW/HIDE
		$("div.my_album").click (
			function () {
				$("div.my_album_list").css({"top":$(this).position().top + 25 + "px","left":$(this).position().left + 5 + "px"}).slideDown("fast");
			}
		);
		$("div.my_album_list").mouseleave (
			function () {
				$(this).slideUp("fast");
			}
		);
		
		//CATEGORY LIST SHOW/HIDE
		$("div.cat_list").click (
			function () {
				$("div.category_list").css({"top":$(this).position().top + 25 + "px","left":$(this).position().left + 5 + "px"}).slideDown("fast");
			}
		);
		$("div.category_list").mouseleave (
			function () {
				$(this).slideUp("fast");
			}
		);

		//HOVER IMAGES
		$(".hover_img").live("mouseenter",
			function () {
				var src_type = this.src.substr(this.src.length - 4, 4);
				this.src = this.src.replace(src_type, "_hover" + src_type);
			}
		);
		$(".hover_img").live("mouseleave",
			function () {
				this.src = this.src.replace(/\_hover/, "");
			}
		);
		
		//FEEDBACK SUBMIT
		$("div.feedback div.button").live ("click",
			function() {
				var txt = $("div.feedback textarea").val();
				var mail = $("div.feedback input[name='email']").val();
				if (mail && txt) {					
					$.post ("/engine/module/feedback.php",
						{
							text: txt,
 						email: mail
						},
						onAjaxSuccess
					);
				} else alert("Заполните все поля!");
				function onAjaxSuccess(reply) {
					$("div.feedback_form").fadeOut("fast",
						function () {
							$("div.feedback_form").empty().append(reply).fadeIn("fast");
						}
					);
				}
			}
		);
		
		//ONRESIZE
		if (!ie6) {
			$(window).resize (
				function() {
					if ($("div.wrapper").width() >= 1375) {
						$("img.user_panel_end").show();
						$("img.menu_photo_end").show();
					}	else {
						$("img.user_panel_end").hide();
						$("img.menu_photo_end").hide();
					}
					FooterCorrect();
				}
			);
		}
		
		//INPUT ACTION
		var input_list = "input, textarea";
		$(input_list).live("focus",
			function () {
				if (this.value == this.title) this.value = "";
			}
		);
		$(input_list).live("blur",
			function () {
				if (this.value == "" || this.value == " ") this.value = this.title;
			}
		);
		
		FooterCorrect();
		
		$("div.banners_three embed").ready(
		 function () {
				FooterCorrect(90);
			}
		);
		
		//SEARCH INPUT BG
		/*var search_input = $("div.input:not(.enter_reg) input");
		if (search_input.val() != "") search_input.removeClass("yandex_search");
		search_input.focusin(
		 function() {
				$(this).removeClass("yandex_search");
		 }
		);
		search_input.focusout(
		 function() {
			 if (this.value == "") $(this).addClass("yandex_search");
		 }
		);*/		
		
		//////////////////////
	}
);

function FooterCorrect (correct) {
	if (!correct) correct = 0;
	$("div.footer").css("position", "relative");
	$("div.wrapper").css("height", "auto");
	if (($("div.wrapper").height() + correct) < $(window).height()) {
		$("div.wrapper").height($(window).height());
		$("div.footer").css({"position":"absolute","bottom":"0px"});
	} else {
		$("div.wrapper").css("height", "auto");
		$("div.footer").css("position", "relative");
	}
}
