$(document).ready(function() {
	if($.browser.msie && $.browser.version == '9.0'){
		$('.green.sub-not').css('margin-left', '-3px');
	}
	$("a.newsletter").fancybox({
			'height'	:	203,
			'padding'	:	0,
			'scrolling'	:	'no',
			'width'		:	450
	});
	
	$("a.recommend").fancybox({
		'height'	: 274,
		'padding'	:	0,
		'scrolling'	:	'no',
		'width'		:	450
	});
	
	$("#main-menu > ul > li").hover(
		function() {
			var $li = $(this);
			var $a = $(this).find('a:first');
			var $sub = $a.next('div');
			$a.addClass('actv');
			$li.parent().find('li div').css('display','none');
			$sub.css('display','block');
			$sub.css('width','auto');
			
			var descH = $sub.find('p:first-child').height() + 4 + "px";
			$sub.find('ul:first').css('min-height',descH);
			
		}, 
		function() {
			var $li = $(this);
			var $a = $(this).find('a:first');
			$a.removeClass('actv');
			$a.next('div').css('display','none');
	});
	
	$('#color ul li: a').click(function(e){
		e.preventDefault();
		var link = $(this).attr('href');
		var id = link.substr(link.lastIndexOf('/')+1)
		$.post($(this).attr('href'), 'id:'+id, function(result){
			var result = eval('(' + result + ')');
			$('#main .bg').attr('class', 'bg');
			$('#main .bg').addClass(result.color);
			$('#main .bg p').remove();
			$('#main .bg h4').html(result.title);
			$('#main .bg ul.lead').replaceWith(result.content);
		})
	});
	
	var winW = 0, winH = 0;
	if (document.body && document.body.offsetWidth) {
	 winW = document.body.offsetWidth;
	 winH = document.body.offsetHeight;
	}
	if (document.compatMode=='CSS1Compat' &&
	    document.documentElement &&
	    document.documentElement.offsetWidth ) {
	 winW = document.documentElement.offsetWidth;
	 winH = document.documentElement.offsetHeight;
	}
	if (window.innerWidth && window.innerHeight) {
	 winW = window.innerWidth;
	 winH = window.innerHeight;
	}

	if (winH > $("body").height()) {
	    //console.info('screen.height: ' + winH);
	    //console.info('body.height: ' + $("body").height());
	    $("body > footer").css("position", "absolute").css("bottom", "0");
	    $("body > #main > footer").css("position", "absolute").css("bottom", "17px");
	}
	
	
	var winW = 0, winH = 0;
	if (document.body && document.body.offsetWidth) {
	 winW = document.body.offsetWidth;
	 winH = document.body.offsetHeight;
	}
	if (document.compatMode=='CSS1Compat' &&
	    document.documentElement &&
	    document.documentElement.offsetWidth ) {
	 winW = document.documentElement.offsetWidth;
	 winH = document.documentElement.offsetHeight;
	}
	if (window.innerWidth && window.innerHeight) {
	 winW = window.innerWidth;
	 winH = window.innerHeight;
	}
	
	//console.info('winW: ' + winW);
	var bgImg = 'hbg1920';
	switch (true) {
		//case winW <= 1920: bgWidth = 1920; break;
		//case winW <= 960: bgImg = 'main-hp'; break;
		case winW <= 1024: bgImg = 'hbg1024'; break;
		case winW <= 1280: bgImg = 'hbg1280'; break;
		case winW <= 1366: bgImg = 'hbg1366'; break;
		case winW <= 1680: bgImg = 'hbg1680'; break;
	}
	$("body#hp").css("background", "url('/tpl/img/bg/" + bgImg + ".jpg') transparent 0px 122px no-repeat");
	
});

