var userIsLogined = false;

var socialLinks = [
"http://vk.com/kotex",
"http://www.facebook.com/pages/Kotex/243437145668544",
"http://twitter.com/#!/KotexRussia",
"http://www.youtube.com/KotexRussia",
"http://www.odnoklassniki.ru/#/group/51787250532590"
];

var t = this;

$(document).ready(function(){
	
	if ($("#vhod").width() < 50){
		$("#vhod").width('150px');
	} else if ($("#vhod").width() > 460){
		$("#vhod").width('460px');
	} else {
		$("#vhod").width('auto');
	}
	
	if ($("#vhod").width() > 200){
		$("#vhod").html("<div>" + $("#vhod").html() + "</div>");
		var length = $("#vhod div").width();
		$("#vhod").width(length + "px");
		$("#vhod div").width(length + "px");
		$("#vhod div").easyRotate({degrees: 1});
	}
	
	$('#rightpart').css('marginTop', ($("#vhod").width() * 0.035 - 14) + 'px');
	
	$("#in_container").mouseenter(function(e){
		$("#in_container").stop();
		$("#in_container").animate({
		    marginTop: "-7px",
		    height: "57px"
		}, 300 );
	}).mouseleave(function(e){
		$("#in_container").stop();
		$("#in_container").animate({
		    marginTop: "0px",
   		    height: "50px"
		}, 1000 );
	});	
		
	var elements = $("#entrance div");
	var lst = elements.eq(elements.length - 1);
	lst.addClass('lastdiv');
	var prelst = elements.eq(elements.length - 2);
	prelst.addClass('prelastdiv');
	
	/*
	$('#content_container').height($('#content_container div.center').height());
	*/
	$('#content_container div.center').css('marginLeft','0px');
	$('#content_container div.center').css('marginRight','0px');

	$('#entrance').hide();
	$('#entrance').prepend('<a href="javascript:void(0)" id="closebtn"></a>');
	
	setClickLoginPopup();
	
	var prods = $('#roll ul li').get()
	$.each(prods, function(index, closure){
		$(this).mouseover(function(e){
			$(this).addClass('hover');
		});
		$(this).mouseout(function(e){
			$(this).removeClass('hover');			
		});
	});
	
	var socs = [];
	$.each(socialLinks, function(index, closure){
		socs[index] = $('<a href="' + socialLinks[index] + '"></a>'),
		$("#socials").append(socs[index]);
	});

	$('#logo').click(function(e){
	t.location.href = "/"
	});
	
	//
	var divs = $('#chooser div').get();
	$.each(divs, function(index, closure){
		$(this).click(function(e){
			
			$('#chooser').animate({
					backgroundPosition: '0px ' + (-237 + (1 + index)*79) + 'px'
			}, 1000, function() {
				$('#chooser').css('backgroundPosition', '0px ' + (-237 * 5 + (index +1 )*79)  + 'px');
			});
			// Animation complete.
		});
	});
	
	$('#kimberly').click(function(){
		window.location.href = "http://www.kimberly-clark.ru";
	});
	
	$('#kimberly').jrumble({
		rumbleEvent: 'hover',
		rumbleSpeed: 120,
		rangeX: 1,
		rangeY: 1,
		rangeRot: 3
	});
});


function showLoginPopup(e){
	$('#in_container').css('cursor', 'auto');
	$('#in_container').unbind('click');
	$('#entrance').fadeIn();
	$('#zigzag').fadeOut();
	$('#closebtn').click(function(e){
		$('#in_container').css('cursor', 'pointer');
		$('#entrance').fadeOut();
		$('#zigzag').fadeIn();
		$('#closebtn').unbind('click');
		setTimeout(setClickLoginPopup, 400);
	});
}

function setClickLoginPopup(){
	$('#in_container').click(showLoginPopup);
}

function checkIsUserRegistered(){
	if (!userIsLogined){
		showRegisterMessage();
	}
}

function showRegisterMessage(){
 	$('#content_container .center').prepend('<div id="registerMessage"><b>Вы не авторизованы!</b> Чтобы сохранить результат нужно <a href="/Registration.aspx">авторизоваться</a> или <a href="/Registration.aspx">зарегистрироваться</a>.<a href="javascript:void(0);" class="close"></a></div>');
 	$("#registerMessage a.close").click(function(){
 		$('#registerMessage').fadeOut();
 	});
 	/*
 	setTimeout(function(){
 		$('#registerMessage').fadeOut();
 	}, 10000);
 	*/
}
