﻿$(document).ready(function(){
	fancySetup();
	$('.header_menu_bg td:first').css('background','none');
	$("form.jqtransform").jqTransform();
	$("form#searchForm").jqTransform();
	$("form#addForm2").jqTransform();
	section_item_hover_tog();
	head_cont_hover_tog();
	best_deals();
	resize_a();
	resize_row();
	$('.box .cc').load("/basketPHP.php?get=true");
	$('.jqtransform ul li a').click(function () {
		var val_t = $('option:selected').attr('value');
		window.location='?sp1='+val_t+'#cont_catalog';
	});
	//$('body').find('span').removeAttr('style');
	$('.order_call_bg').click(function () {
		$('.call_bg').fadeIn('500');
		$('body').append('<div class="shadow"></div>');
		$('.shadow').fadeIn('500');
		close();
	});
	/*	var section_item = $('.section_item');
		if(section_item!= null){
			alert(section_item.text());
		}
	/*while(1){
		if(section_item!= null){
			var id_i = $(this).children('.item').attr('id');
			alert(id_i);
		}else{
			break;
		}
	}*/
	$('#addForm2 .jqTransformButton').click(function(){
		$('#addForm2').submit();
	});
});
function fancySetup() {
		$("a.fancy").fancybox({
			'zoomOpacity'	: true,
			'overlayShow'	: true,
			'zoomSpeedIn'	: 300,
			'zoomSpeedOut'	: 500
		});
	}
function close(){
	$('.shadow').click(function () {$('.shadow').fadeOut('500').remove();$('.call_bg').fadeOut('500');});
	$('#close_call').click(function () {$('.shadow').fadeOut('500').remove();$('.call_bg').fadeOut('500');});
}
window.onload = function() {  
 
};  
function section_item_hover_tog(){
	$('.section_item').click(function(){
		var loc = $(this).attr('ahref');
		window.location = loc;
	});
	$('.section_item').mouseenter(function() {
		var this_id = $(this).children('.item').attr('id');
		$(this).addClass('hover').children().addClass('hover');
		$(this).children('.item').css('background-image','url(/upload/catalog/path/hover/'+this_id+'_1.png)')
	}).mouseleave(function() {
		var this_id = $(this).children('.item').attr('id');
		$(this).removeClass('hover').children().removeClass('hover');
		$(this).children('.item').css('background-image','url(/upload/catalog/path/'+this_id+'_1.png)')
    });
}
function best_deals(){
	var sc_w = $('.best_deals .center').innerWidth();
	$('.best_deals .right_scroll').click(function(){
		$('.best_deals .center').animate({
			scrollLeft: '+='+(sc_w-100)
		}, 2000);
		head_cont_hover_tog();
	});
	$('.best_deals .left_scroll').click(function(){
		$('.best_deals .center').animate({
			scrollLeft: '-='+(sc_w-100)
		}, 2000);
		head_cont_hover_tog();
	});
}
function resize_a(){
var sh_1 = $('.section').innerHeight();
	//$('.test').css('height', sh_1);
	var i = 0;
	while(1){
		var text = $('.section_item.id'+i+' a').text();
		//alert(text);
		if(text==''){
			break;
		}else{
			var sh = $('.section_item.id'+i+' a').innerHeight();
			if(sh>36){
			var mt=(sh-36);
				$('.section_item.id'+i+' a').css('margin-top', '-'+mt+'px');
			}
			i++;
		}
	}
}
function resize_row(){
	var i = 0;
	while(1){
	var text = $('#row'+i).text();
		if(text == ''){
			break;
		}else{
			var y = 0;
			var max_h= 0;
			var max_img_h = 0;
			while(y<3){
				var this_h = $('#row'+i+' td:nth-child('+y+') .c').innerHeight();
				var this_img_h = $('#row'+i+' .img_bg:eq('+y+')').innerHeight();
				//alert('#row'+i+' .img_bg:nth-child('+y+') = '+this_img_h);
				if ( this_h > max_h ){max_h = this_h;}
				if ( this_img_h > max_img_h ){max_img_h = this_img_h;}
				y++;
			}
			$('#row'+i).children('td:eq(0)').css('padding-bottom', '30px');
			$('#row'+i).children('td:eq(1)').css('padding-bottom', '30px');
			$('#row'+i).children('td:eq(2)').css('padding-bottom', '30px');
			$('#row'+i+' td table.this_item').css('height' , max_h);
			$('#row'+i+' td table.img_bg .c').css('height' , max_img_h);
			i++;
		}
	}
}
function head_cont_hover_tog(){
	$('.best_deals .center td').mouseenter(function() {
		var best_deals_p = $(this).position();
		var best_deals_l = best_deals_p.left;
		var best_deals_w = $(this).innerWidth()-3;
		$('.help',this).css({'width' : best_deals_w});
		var best_deals_h = $(this).innerHeight();
		var h_help = $('.help',this).innerHeight();
		best_deals_p = (best_deals_p.top + best_deals_h)-h_help+10;
		$('.help',this).css({'top' : best_deals_p, 'left' : best_deals_l, 'margin-bottom' : '-'+best_deals_p+'px'}).fadeIn(500);
	}).mouseleave(function() {
		$('.help',this).fadeOut(500);
	});
}
