$(document).ready(function(){

/** DropDown Menu */
$('li.sub').hover(
	function() {
	$(this).addClass('down');
},
	function() {
	$(this).removeClass('down');
});
$('.MainMenu li').hover(
	function() {
	$('.DDown',this).show();
},
	function() {
	$('.DDown',this).hide();
});


/** Issue SlideShow */
/*$('.IssueSlider').fadeIn(1000);
$('#IssueSlider li img').fadeTo(1000, 0.7);
$('#it1').addClass('active');
$('.th1').fadeTo(1000, 1);
$('li').hover(
	function () {
		$('li').removeClass('active'),
		$(this).addClass('active')
});

$('#IssueSlider li').hover(function() {
    $('.IssueSlider').animate({left: -($(this).prevAll().length)*708 + "px"}, 300),
    $('.th2, .th3, .th4').fadeTo(300, 0.7),
    $('img',this).fadeTo(300, 1)
});*/
/*
$('#it1').hover(
	function () {
		$('.IssueSlider').animate({left: "0px"}, 300),
		$('.th2, .th3, .th4').fadeTo(300, 0.7),
		$('img',this).fadeTo(300, 1)
});
$('#it2').hover(
	function () {
		$('.IssueSlider').animate({left: "-708px"}, 300),
		$('.th1, .th3, .th4').fadeTo(300, 0.7),
		$('img',this).fadeTo(300, 1)
});
$('#it3').hover(
	function () {
		$('.IssueSlider').animate({left: "-1416px"}, 300),
		$('.th1, .th2, .th4').fadeTo(300, 0.7),
		$('img',this).fadeTo(300, 1)
});
$('#it4').hover(
	function () {
		$('.IssueSlider').animate({left: "-2124px"}, 300),
		$('.th1, .th2, .th3').fadeTo(300, 0.7),
		$('img',this).fadeTo(300, 1)
});*/


/** Part SlideShow */
$('.PartSlider, .psControls').fadeIn(1500);
$('.psControls span').hover(
	function () {
		$('.psControls li').removeClass("active"),
		$('.psControls li',this).addClass("active")
});


/** Part slider */
$('.psControls li').hover(
	function () {
		$('span').removeClass('active'),
		$('span',this).addClass('active')
});
$('.psControls .alnk1').hover(
	function () {
		$('.PartSlider').animate({left: "0px"}, 300)
});
$('.psControls .alnk2').hover(
	function () {
		$('.PartSlider').animate({left: "-710px"}, 300)
});
$('.psControls .alnk3').hover(
	function () {
		$('.PartSlider').animate({left: "-1420px"}, 300)
});


/** Part News Pics */
$('.PartNews .pic').hover(
	function() {
	$('div',this).fadeTo(300, 1);
},
	function() {
	$('div',this).hide();
});


/** Poll Toggle */
$('#tglF, #tglM').click(
	function () {
		$('h3').removeClass('active'),
		$(this).addClass('active')
});
$('#tglF').click(
	function () {
		$('#pollF').fadeIn(300),
		$('#pollM').hide()
});
$('#tglM').click(
	function () {
		$('#pollM').fadeIn(300),
		$('#pollF').hide()
});


/** Read More Block */
$('.artLister li').hover(
	function () {
		$('span').removeClass('active'),
		$('span',this).addClass('active')
	},
	function () {
		$('span',this).removeClass('active')
});
$('.artLister li').hover(
	function () {
		$('.artAnnounce',this).fadeTo(300, 1.0)
	},
	function () {
		$('.artAnnounce',this).hide()
});



/** Cosmo Shop */
$('#ShopLister a').click(
	function () {
		$('#ShopLister a').removeClass('active'),
		$(this).addClass('active')
});
$('#shl1').click(
	function () {
		$('#shop1').show()
		$('#shop2, #shop3, #shop4').hide()
});
$('#shl2').click(
	function () {
		$('#shop2').show()
		$('#shop1, #shop3, #shop4').hide()
});
$('#shl3').click(
	function () {
		$('#shop3').show()
		$('#shop1, #shop2, #shop4').hide()
});
$('#shl4').click(
	function () {
		$('#shop4').show()
		$('#shop1, #shop2, #shop3').hide()
});


/** Rabota.Ru */
$('#JobLister a').click(
	function () {
		$('#JobLister a').removeClass('active'),
		$(this).addClass('active')
});
$('#jl1').click(
	function () {
		$('#jgr1').show()
		$('#jgr2, #jgr3, #jgr4').hide()
});
$('#jl2').click(
	function () {
		$('#jgr2').show()
		$('#jgr1, #jgr3, #jgr4').hide()
});
$('#jl3').click(
	function () {
		$('#jgr3').show()
		$('#jgr1, #jgr2, #jgr4').hide()
});
$('#jl4').click(
	function () {
		$('#jgr4').show()
		$('#jgr1, #jgr2, #jgr3').hide()
});


/** LazyLoad */
if (!$.browser.msie) {
    if (typeof $("img").lazyload == 'undefined')
    {

    } else    {
        $("img").lazyload({
		placeholder : "img/0.gif",
		threshold : 10000
        });
    }
}

AuthForm.create('a.auth_link');

});

/**fade auth form**/
var AuthForm = {
	_isform: false,
    create: function(obj){
		if (!this._isform)
		{
		    var okLinkHtml = '<a title="Войти используя аккаунт на Одноклассники.Ру" class="odnoklassniki_login_button" href="http://www.cosmo.ru/auth/ok.php?backurl=http://cosmo.ru/">Войти используя аккаунт Odnoklassniki.Ru</a>';
			$("body").append('<div style="display:none" id="layer_reg_form"><form class="reg_form" action="#" method="post"><label for="input_login">E-mail или логин:</label><div class="wr_input"><input name="login" id="input_login" type="text" value="" class="inputtext"></div><label for="input_password">Пароль:</label><div class="wr_input last"><input name="password" id="input_password" type="password" value="" class="inputtext"></div><a class="forgot_pass" style="display:inline;" href="'+SocialCore.apiUrl+'login/recover.do">Забыли пароль?</a>&nbsp;&nbsp;&nbsp;<a style="font-size:11px;color: rgb(171,171,171); text-decoration:underline;" href="'+SocialCore.apiUrl+'register.do">Регистрация</a><input type="submit" name="" class="submit_btn" value=""></form>' + okLinkHtml + '</div>');
			this._isform = true;
		}
		$(obj).bind('click', this.show);
    },
	show: function(){
		$.popupWindow.open({
				width: 300,
				height: 165,
				overlayOpacity: 0.4,
				innerHtml: $("#layer_reg_form").html()
			});

		$('#popup_window .reg_form').submit(function(){
			$("#popup_window_content .reg_error").remove();
            SocialAuth.login(
				$('#popup_window .reg_form input[type=text]').attr('value'),
				$('#popup_window .reg_form input[type=password]').attr('value'));
			return false;
		});
		return false;
	},

    showError: function() {
        if (this._isform) {
            $("#popup_window_content").append("<div class=\"reg_error\">Неверный email, логин или пароль</div>");
        }
    }
}

