$.fn.extend({
	inputHint: function()
	{
		var alt=this.attr("alt");

		if(alt)
		{
			var oldcolor=this.css("color");
			
			this.val(alt).css({color:"#000000"});

			this.mouseenter(function(){
				if($(this).val()==alt)
					$(this).val("").css({color:"#000000"});
				else
					$(this).css({color:oldcolor});
			}).mouseleave(function(){
				if($(this).val()=="")
					$(this).val(alt).css({color:"#000000"});
				else
					$(this).css({color:oldcolor});	
			}).blur(function(){
				if($(this).val()!="" && $(this).val()!=alt)
					$(this).css({color:oldcolor});
			}).focus(function(){
				if($(this).val()!="")
					$(this).css({color:oldcolor});
			}).keyup(function(){
				if($(this).val()!="")
					$(this).css({color:oldcolor});
			});;
		}
	}
});

$(document).ready(function ()
{
    $(".slideshow").cycle({
                fx: "fade"
        });

	Cufon.replace('.menu div');
	Cufon.replace('.link');
	Cufon.replace('h4');
	Cufon.replace('h3');
	Cufon.replace('h1');
	Cufon.replace('.txt');
	Cufon.replace('.bulletin');
	Cufon.replace('.group');
	Cufon.replace('.page div');
	Cufon.replace('.course');

	jQuery.ifixpng('i/s.gif');
	jQuery('img, .bgPng').ifixpng();
	jQuery('td, .bgPng').ifixpng();
	jQuery('div, .bgPng').ifixpng();
	jQuery('a, .bgPng').ifixpng();
	jQuery('li, .bgPng').ifixpng();
	jQuery('body, .bgPng').ifixpng();
	$(".menu_over").mouseenter(function(){
		if(parseInt($(this).attr("rel")))
			$.t=parseInt($(this).attr("rel"));
		else
			$.t=106;
			
		$(this).css('cursor', 'pointer');
		$(this).find(".shadow").stop().animate({top:$.t}, 300)
	}).mouseleave(function(){
		$(this).css('cursor', 'default');
		$(this).find(".shadow").stop().animate({top:0}, 300)
	}).click(function(){
		window.location.href=$(this).find(".link a").attr("href");
	})
	
	$(".icos .ico").mouseenter(function(){
		$(this).find(".hid").fadeIn("fast");
	}).mouseleave(function(){
		$(this).find(".hid").fadeOut("fast");
	});

	function forceModalWindow(imw)
	{
		$('#galleryWindow').modal({persist:true, overlayCss: {backgroundColor: '#000'},containerCss:{width: imw},onClose:function(){$.modal.close();}});
	}
	
$("#various, #various2, #various3, #various4, #various5, #various6, #various7, #various8, #various9, #various10, #various11, #various12, #various13, #various14, #various15, #various16, #various17, #various18, #various19, #various20, #various21, #various22, #various23, #various24, #various25, #various26, #various27, #various28, #various29, #various30").fancybox({
                'width'                         : '30%',
                'height'                        : '35%',
        'autoScale'             : true,
        'transitionIn'          : 'none',
                'transitionOut'         : 'none',
                'type'                          : 'iframe'
        });

	$("#request").click(function(e){
		e.preventDefault();

		$("#galleryWindow").fadeIn("fast");
		$("#galleryWindow #form").html("<div id='current_form'>"+$("#request_form").html()+"</div>");
		$("#galleryWindow .mainImage").css({'background-image':'none', 'background-color':"#FFFFFF", "width":341, "height":385});
		$("#galleryWindow input,#galleryWindow textarea").each(function(){$(this).inputHint()});
		
		$("#current_form .zbutton").click(function(e){
			e.preventDefault();
			if($("#current_form").attr("rel") == "running") return;
			if($("#current_form .zname").val()!=$("#current_form .zname").attr("alt"))
				if($("#current_form .zemail").val()!=$("#current_form .zemail").attr("alt"))
					if($("#current_form .zphone").val()!=$("#current_form .zphone").attr("alt"))
						if($("#current_form .zmessage").val()!=$("#current_form .zmessage").attr("alt"))
						{
							$("#current_form").attr("rel", "running");
							$.ajax({
								type: "POST",
								url: "/sendorder/",
								data: {course:$("#current_form .zcourse").html(), name:$("#current_form .zname").val(),email:$("#current_form .zemail").val(),phone:$("#current_form .zphone").val(),message:$("#current_form .zmessage").val()},
								success: function(msg){
									alert(msg);
									$.modal.close();
									$("#current_form").attr("rel", "");
								}
							});
						}
						else
							alert("Заполните поле комментария");
					else
						alert("Заполните поле телефона");
				else
					alert("Заполните поле электронной почты");
			else
				alert("Заполните поле имени");
	 	});
		
		$("#current_form .zibutton").click(function(e){
			e.preventDefault();
			if($("#current_form").attr("rel") == "running") return;
			if($("#current_form .zname").val()!=$("#current_form .zname").attr("alt"))
				if($("#current_form .zsubject").val()!=$("#current_form .zsubject").attr("alt"))
						if($("#current_form .ztext").val()!=$("#current_form .ztext").attr("alt"))
						{
							$("#current_form").attr("rel", "running");
							$.ajax({
								type: "POST",
								url: "/sendfeedback/",
								data: {name:$("#current_form .zname").val(),subject:$("#current_form .zsubject").val(),text:$("#current_form .ztext").val(),type:$("#current_form input:radio:checked").val()},
								success: function(msg){
									alert(msg);
									$.modal.close();
									$("#current_form").attr("rel", "");
								}
							});
						}
						else
							alert("Заполните поле сообщения");
				else
					alert("Заполните поле темы");
			else
				alert("Заполните поле имени");
	 	});
		forceModalWindow(341);
	})

	$(".gallery").click(function(e){
		e.preventDefault();
		$("#galleryWindow").fadeIn("fast");

		$current=parseInt($(this).attr("rel"));

		$main=$("#galleryWindow .mainImage");
		
		$main.css({'background-image':"url("+$(this).attr("href")+")", "width":$(this).attr("w"), "height":$(this).attr("h")});
		$main.find(".next").unbind("click").bind("click", function(e){
			e.preventDefault();

			if(($current)<$(".gallery").size())
			{
				$current++;
				openGal($current);

				if($current==$(".gallery").size())
					$(this).hide();
			}
		});
		$main.find(".prev").unbind("click").bind("click", function(e){
			e.preventDefault();
			if($current>1)
			{
				$current--;
				openGal($current);

				if($current==1)
					$(this).hide();
			}
		});
		forceModalWindow($(this).attr("w"));
	})
	
	function openGal(num)
	{
		$t=$(".gallery[rel='"+num+"']");
		$main=$("#galleryWindow .mainImage");
		$main.css({'background-image':"url("+$t.attr("href")+")", "width":$t.attr("w"), "height":$t.attr("h")})
		$main.find(".next").show();
		$main.find(".prev").show();
		
		$.modal.close();
		forceModalWindow($t.attr("w"));
	}
	
	
});

$(function(){
		var msie6 = $.browser == 'msie' && $.browser.version < 7;
		
		if (!msie6 && $('#hotlinks').size()>0)
		{
			var top = $('#hotlinks').offset().top - parseFloat($('#hotlinks').css('margin-top').replace("auto", 0));

			$(window).scroll(function (event)
			{
				var y = $(this).scrollTop();
				if (y >= top)
				{
					$('#hotlinks').addClass('fixed');
				}
				else
				{
					$('#hotlinks').removeClass('fixed');
				}
			});
		}
    })

