﻿function startFlash() {
	flashembed("header-flash", {
		src: "flash/header-flash.swf",
		wmode: 'transparent',
		allowfullscreen: false,
		w3c: true,
		version: [10, 0],
		onFail: function(){flashFalse()}
	})
};
function flashFalse(){$('#header-flash').append('<div class="fail">&nbsp;</div>')};
function LabelsClean(){
	var	inputLabels=$('input.form-input').val();
	$('input.form-input').each(function(i){
		var	inputLabel=$(this).val();
		$(this).focus(function(){if ($(this).val() == inputLabel) {$(this).val('')}});
		$(this).blur(function(){if ($(this).val() == '') {$(this).val(inputLabel)}})
	})
};

function setShadow() {
	if ($.browser.msie) {
		$('#slogan').textShadow();
		$('#header .contact .phone').textShadow();
	}
};
function clearBigPhoto(){
	$('#img').remove();
	$('#big-photo').removeAttr('style');
	$('#big-photo .close').removeAttr('style');
	$('#big-photo .progress').removeAttr('style');
};
function setFooter(){
	if (($.browser.msie && $.browser.version == 6) || ($.browser.msie && $.browser.version == 7)) {
		$('#footer').hide(0);
		$('#footer').show(0)
	}
};
function BuildPage(){
	setShadow();
	LabelsClean();
	$('#top-menu ul li:first').css({'padding':'0px','background':'none'});
	if ($('#center .production .items .item a').length>0) {
		var	el=$('#center .production .items .item'),
				l=el.length,
				eq=[el.length-1,el.length-2,el.length-3],
				t=(Math.floor(l/3))*3;
		if (t==l) {t=l-3};
		for (var i=0, len=eq.length; i<len; i++) {
			if (eq[i]>t || eq[i]==t) {el.eq(eq[i]).css({'background':'none','padding':'0'})}
		};
		$('body').append('<div id="tip-block">&nbsp;</div>');
		$("#center .production .items .item a[title]").tooltip({
			tip: '#tip-block',
			position: 'bottom right',
			offset: [-50, -150]
		});
	};
	$('.catalog .items .item').each(function(i){
		var	Himg=$(this).find('.image:first').height(),
				HDescr=$(this).find('.description:first').height(),
				PDescr=37;
		if (Himg>HDescr+PDescr) {$(this).find('.description:first').height(Himg-PDescr)}
		else {$(this).find('.image:first').height(HDescr+PDescr)}
	});
	if ($('#main-colume .item-one').length == 1) {
		$('body').append('<div class="overlay" id="big-photo"></div>');
		$('#big-photo').append('<a class="prev">назад</a>');
		$('#big-photo').append('<a class="next">вперед</a>');
		$('#big-photo').append('<div class="info"></div>');
		$('#big-photo').append('<img class="progress" src="img/loading.gif" />');
		$('#main-colume .item-one a').overlay({
			target: '#big-photo',
			expose: '#111',
			closeOnClick: false,
			onClose: function() {clearBigPhoto()}
		}).gallery({
			disabledClass: 'inactive',
			template: '<strong>${title}</strong>',
			speed: 100 
		})
	};
//	Обработка корзины, то есть удаление товаров из корзины
	if (document.getElementById('korzina')) {
		$('#korzina .item').each(function(i){
			$(this).find('table span').click(function(){
				$('#korzina .item').eq(i).remove();
				setFooter();
				//тут можно вставить функцию удаления товара из базы
			})
		})
	}
	
	  $(function(){
        $('.slide-out-div').tabSlideOut({
            tabHandle: '.handle',
            pathToTabImage: 'img/profile.gif',
            imageHeight: '122px',
            imageWidth: '40px',
            tabLocation: 'right',
            speed: 300,
            action: 'click',
            topPos: '200px',
            leftPos: '20px',
            fixedPosition: true
        });

    });

};
$(document).ready(function(){BuildPage();startFlash()});
