﻿$(document).ready(function() {
	$(".all_report").mouseover(function() {
		$(".all_report DIV").css("background-position", "5px -31px");
	});
	
	$(".all_report, .all_blog").mouseout(function() {
		$(".all_report DIV, .all_blog DIV").css("background-position", "5px 0px");
	});
	
	$(".all_blog").mouseover(function() {
		$(".all_blog DIV").css("background-position", "5px -29px");
	});
	
	$(".li_add").mouseover(function() {
		$(".li_add").css("background", "url(" + $config.img + "/li_add_activ.png) no-repeat 0 0px");
	});
	
	$(".li_add").mouseout(function() {
		$(".li_add").css("background", "url(" + $config.img + "/li_add.png) no-repeat 0 0px");
	});
	
	$(".li_rss").mouseover(function() {
		$(".li_rss").css("background", "url(" + $config.img + "/li_rss_activ.png) no-repeat 0 0px");
	});
	
	$(".li_rss").mouseout(function() {
		$(".li_rss").css("background", "url(" + $config.img + "/li_rss.png) no-repeat 0 0px");
	});
	
	$(".li_tw").mouseover(function() {
		$(".li_tw").css("background", "url(" + $config.img + "/li_tw_activ.png) no-repeat 0 0px");
	});
	
	$(".li_tw").mouseout(function() {
		$(".li_tw").css("background", "url(" + $config.img + "/li_tw.png) no-repeat 0 0px");
	});
	
	$(".star").mouseover(function() {
		$("#static").show();
	});
	
	$(".star").mouseout(function() {
		$("#static").hide();
	});
	
	$(".bg_title").css("margin-top", "-"+($(".bg_title").height()+10)+"px");

	$(".select_city_btn").click(function() {
		if ($('#select_city').is(':visible')) {
			$('#select_city').hide();
		} else {
			$('#select_city').show();
		}
	});

	$('#select_city .city_title').click(function() {
		if ($('#select_city').is(':visible')) {
			$('#select_city').hide();
		}
	});

	$(".bg_main, .div_top, .logo, .menu_li_top, .title_top_right, .footer, .select_content").click(function() {
		$('#select_city').hide();
	});
	
	change_list_cinema_r();
	change_size_block();
	change_photo_rep("news_photo_report", "report");
//	change_photo_rep("news_blogs", "div_news_blogs");
	change_submenu();

	if ( $(".mainmenu .activ").length ) {
		var move = $(".mainmenu .activ").offset().left - $('.submenu').width()/2;
		if (move < $('.submenu').width()/2) move += $('.submenu').width()/2;
		move += parseInt($(".submenu").css('padding-left'));
		$(".submenu").animate({ paddingLeft: move }, 500);
	}

	change_event_center();
//	change_photo_gallery();
	change_in_treiler();
	change_min_rasp();

	/**
	 * Login via .div_top
	 */
	if ($('.header-login-form').length) $('.header-login-message').hide();
	$('.div_top .buttop').click(function() {
		var form = $(this).parents('form:first');
		$.ajax({
			url: form.attr('action'),
			type: 'POST',
			data: {
				login: form.find('input#login').val(),
				password: Just.sha1(form.find('input#pass').val()+form.find('input#auth_secure_key').val()),
				secure: 1
			},
			dataType: 'json',
			success: function(res) {
				var lf = $('.div_top .header-login-form');
				var lm = $('.div_top .header-login-message');
				if (res.status == 0) {
					lm.find('span').text(res.message);
					lf.fadeOut(200, function() {
						lm.fadeIn(200).delay(1000).fadeOut(200, function() {lf.fadeIn(200)});
					});
				} else if (res.status == 1) {
					lm.find('span').text(res.message);
					lf.fadeOut(200, function() {
						lm.fadeIn(200).delay(1000).fadeOut(200, function() {location.reload(true)});
					});
				}
				return false;
			}
		});
		return false;
	});
});

$(window).resize(function() {
	change_list_cinema_r();
	change_size_block();
	change_photo_rep("news_photo_report", "report");
//	change_photo_rep("news_blogs", "div_news_blogs");
	change_event_center();
//	change_photo_gallery();
	change_in_treiler();
	change_min_rasp();
	change_submenu();
});

function change_submenu() {
	$(".clubs").width() != null ? $(".clubs .submenu").css("width", $(".mainmenu .activ").offset().left+($(".submenu UL").width()/2)) : '';
	$(".theatre").width() != null ? $(".theatre .submenu").css("width", $(".mainmenu .activ").offset().left+($(".submenu UL").width()/2)) : '';
}

function change_in_treiler() {
	if ($(".big_treiler").width()!=null) {
		place_tr = ($(".big_treiler").width() - 620);
		count_tr = $(".mintreiler").length
		count_tr == 0 ? count_tr = $(".mintreiler2").length : '';
		if (place_tr > 220 && count_tr == 1) {
			$(".place_tr").width("180px");
			$(".mintreiler").attr("class", "mintreiler2");
			$(".mintreiler_activ").attr("class", "mintreiler_activ2");
		} else if (place_tr > 430) {
			$(".place_tr").width("400px");
			$(".mintreiler").attr("class", "mintreiler2");
			$(".mintreiler_activ").attr("class", "mintreiler_activ2");
		} else {
			$(".place_tr").width("100%");
			$(".mintreiler2").attr("class", "mintreiler");
			$(".mintreiler_activ2").attr("class", "mintreiler_activ");
		}
	}
}

function change_min_rasp() {
	if ($(".right_rasp").width()!=null) {
		if ($(".content-inner").width() - $(".big_poster").width() > 420) {
			$(".right_rasp").css("width", "50%");
		} else {
			$(".right_rasp").css("width", "33%");
		}
	}
}

function change_event_center() {
	$(".content-inner").css("width", ($(".inner_right").width()-$(".inner_advare").width())-140);
}

function change_photo_gallery() {
	if ($(".photo_content").width()!=null) {
		if ($(".g4").width() > 800) {
			$(".srt_left_gal, .srt_right_gal").css("display", "inline");
		} else {
			$(".srt_left_gal, .srt_right_gal").css("display", "none");
		}
		$(".jScrollPaneContainer").css("width", ($(".g4").width()-16)+"px");
		$(".jScrollPaneTrack").css("width", ($(".g4").width()-58)+"px");
		$("#scroll-box").css("width", ($(".g4").width()-16)+"px");
		
		imgs = $("IMG", ".scroll-box P");
		all = 0;
		for (i=0;i<imgs.length;i++) {
			all+=$(imgs[i]).width()+10;
		}
		$(".scroll-box p").css("width", all);
	}
}

function change_list_cinema_r() {
	width_all = $(".pb50ie6").width() - $(".list_cinem_f").width() - $(".list_cinema_com").width()-110;
	width_div = $(".lcf_f DIV ").width()+30;
	$(".lcf_f").css("height", (Math.floor(($(".lcf5").height()+50)/175)*175)+5);
	$(".list_cinema_r").width(width_all);
	count = Math.floor(width_all/width_div);
	(width_all-(count*width_div))/count-0 < 0 ? mar = 0 : mar = (width_all-(count*width_div))/count-10;

	(width_all-(count*width_div))/count<0 ? w = (width_all-(count*width_div))/count*parseInt(-1) : w = (width_all-(count*width_div))/count;
	count == 1 ? w = parseInt(-10) : '';
	$(".lcf_f DIV").css("margin-right", w);
	
}

function change_size_block() {
	if (document.body.clientWidth > 1200) {
//		$(".mainmenu LI ").css("font-size", "120%");
//		$(".div_submenu").css("margin-top", "18px")
		$(".sel_city").css("width", "33%");
		$(".title_top_right").css("width", "25%");
		$(".inp_search").css("width", "80%");
		$(".menu_li_top").css("margin", "22px 3% 0 3%");
//		$(".mainmenu LI.activ, .mainmenu LI.activ2").css("height", "33px");
	} else {
//		$(".mainmenu LI ").css("font-size", "100%");
//		$(".div_submenu").css("margin-top", "14px");
		$(".sel_city").css("width", "25%");
		$(".title_top_right").css("width", "30%");
		$(".inp_search").css("width", "70%");
		$(".menu_li_top").css("margin", "22px 1% 0 2%");
//		$(".mainmenu LI.activ, .mainmenu LI.activ2").css("height", "29px");
	}
}

function change_photo_rep(div_id, div_class) {
	marright = 20;
	all_width = $("#"+div_id).width()-40;
	rep_width = $("."+div_class).width();
	mar = parseInt($("."+div_class).css("margin-right"));
	
	count = Math.floor(all_width/rep_width);

	marright > parseInt((all_width - count*rep_width)/count) ? '' : marright = parseInt((all_width - count*rep_width)/count);
	//alert(mar-right);
	$("."+div_class).css("margin-right", parseInt((all_width - count*rep_width)/count));
}

function change_text(id, text) {
	if ($("#"+id).val() == text) {
		$("#"+id).attr("value", "");
	} else if ($("#"+id).val() == ''){
		$("#"+id).attr("value", text);
	}
}

function div_close(id) {
	$("#"+id+" .newstxt").slideUp(500);
	setTimeout('$("#'+id+'").attr("class", "in_news_right")', 500);
}
