﻿$(document).ready(function() {
	change_product(1, "product");
	change_news(1, "news_li");
	movie_center();
	
	$(".product LI A, .ul_port LI A").mouseover(function() {
		$("#li_"+this.id+" A").attr("class", "activ");
	});
	
	$(".product LI A, .ul_port LI A").mouseout(function() {
		$("#li_"+this.id+" A").attr("class", "");
	});
	
	$('.txtphone').gradientText({
        colors: ['#d12530', '#f6645e']
    });
	
	$("#text_map_google").click(function() {
		$("#text_map_google").hide();
		$("#text_map_ya").show();
		$("#mdata").animate({marginTop:"-362px"});;
	});
	$("#text_map_ya").click(function() {
		$("#text_map_google").show();
		$("#text_map_ya").hide();
		$("#mdata").animate({marginTop:"0"});;
	});
});


$(window).resize(function() {
	change_product(2, "product");
	change_news(2, "news_li");
	movie_center();
});

function movie_center() {
	offleft = $(".mainmenu LI.activ").offset().left+($(".mainmenu LI.activ").width()/2)-5-$(".div_top").offset().left;
	off_left = $(".mainmenu LI.activ").offset().left+($(".mainmenu LI.activ").width()/2);
	
	if (offleft>0) {
		$(".div_top").css("background-position", offleft+"px 0");
		$(".strup").css("background-position", offleft+"px 0");
		$(".submenu DIV").css("margin-left", offleft-(($(".submenu DIV").width()/2)-25)+"px");
	}
	
	$(".acenter .inner_right").css("margin-left", "0");
	if (((((document.body.clientWidth-offleft-80)*100)/document.body.clientWidth)-3) > 60) {
		w = '60%';
	} else {
		w = (((document.body.clientWidth-offleft-80)*100)/document.body.clientWidth)-3+"%";
	}
	$(".acenter .inner_right").css("width", w);
	$(".acenter .inner_left").css("width", offleft-100);
	$(".acenter .inner_left").css("margin-right", "20px");
	$(".acenter .title").css("margin-left", "-"+$(".title SPAN").width()/2+"px");
	
	$(".m0ls1, #alcenter").css("text-align", "left");
	$(".m0ls1 SPAN").css("margin-left", (off_left-$(".inner_right").offset().left-$(".m0ls1 SPAN").width()/2+"px"));
	$("#alcenter SPAN").css("margin-left", (off_left-$(".inner_right").offset().left-13-$("#alcenter SPAN").width()/2+"px"));
	$(".sel, .vkl").css("margin-left", (off_left-$(".inner_right").offset().left-$(".sel").width()/2+"px"));
	//$(".sel, .vkl").css("margin-left", (off_left-$(".inner_right").offset().left-$(".sel").width()/2)/2+"px");
	$(".typeyear SPAN").css("margin-left", offleft-$(".typeyear SPAN").width()-25);
}

function change_product(type, cls) {
	width = $("."+cls).width() - 35 -20;
	prod_li = $("LI", "."+cls);
	all = count = p = 0;
	for (i=0; i<prod_li.length; i++) {
		if ($(prod_li[i]).width()+all+50 < width) {
			all+=$(prod_li[i]).width()+50;
			count++;
		}
	}
	count >=5 ? count = 5 : '';
	padd = (width-all)/count;
	type == 1 ? '' : p = 15;
	count = 4 ? padd+=20 : '';
	$("."+cls+" LI").css("margin-right", (padd-p)+"px");
}

function change_news(type, cls) {
	width = $("."+cls).width();
	prod_li = $("DIV", "."+cls);
	all = count = 0;
	for (i=0; i<prod_li.length; i++) {
		if ($(prod_li[i]).width()+all < width) {
			all+=$(prod_li[i]).width();
			count++;
		}
	}
	p = Math.round(100/count)-3;
	p < 20 ? p = 22 : '';
	(width*22)/100 < 260 ? p = 30 : p = 22;
	$("."+cls+" LI").css("width", (p)+"%");
}

function change_text(id, text) {
	if ($("#"+id).val() == text) {
		$("#"+id).attr("value", "");
	} else if ($("#"+id).val() == ''){
		$("#"+id).attr("value", text);
	}
}

function display_select() {
	if ($(".sel").attr("class") == "fl sel") {
		$(".sel").attr("class", "fl sel activ");
		$(".vkl").animate({opacity: 'toggle'}, 200);
		if ($.browser.msie) {} else {$(".vkl").css("background", "url(/images/bg_select.png)");}
	} else {
		$(".sel").attr("class", "fl sel");
		$(".vkl").animate({opacity: 'toggle'}, 200);
	}
}

