// JavaScript Document

var loading = '<img src="http://www.fitelia.pl/images/loading.gif" alt="loading" align="absmiddle" /> wczytywanie...';

/* plugin */
jQuery.fn.dwFadingLinks = function(settings) {
	settings = jQuery.extend({
		color: '#ff8c00',
		duration: 500
	}, settings);
	return this.each(function() {
		var original = $(this).css('color');
		$(this).mouseover(function() { $(this).animate({ color: settings.color },settings.duration); });
		$(this).mouseout(function() { $(this).animate({ color: original },settings.duration); });
	});
}

function splitHash(url) {
	var string = location.hash.slice(2).split("_");
	return string;
}

function collapseMenu() {
	$("ul.mainMenu li a").each(function() {
		$(this).next().slideUp();
	});
}

function showRegForm() {
	$("#mainContent").html(loading);
	$.ajax({
		type: 'POST',
		url: this.action,
		data: 'show=registerForm',
		success: function(html) {
			$('#mainContent').html(html);
			$("form[name=register_form]").ajaxForm({
				beforeSubmit: function(data, $form) {
					this.$form = $form;
					if($form.valid()) {
						$form.find("input[type=submit]").attr({"disabled":"true"});
					} else
						return false;
				},
				success: function(data, $form) {
					var validator = this.$form.validate();
					validator.resetForm();
					this.$form.find("input[type=submit]").attr({"disabled":""});
					this.$form.slideUp();
					if(data == "ok") {
						this.$form.next().show();
					} else if (data == "error") {
						this.$form.next().next().show();
					}
		//			alert(data);
				}
			});
			$("#nip").mask("9999999999");
			$("#postcode").mask("99-999");
			$("form[name=register_form]").validate({
				rules: {
					first_name: {
						required: true
					},
					last_name: {
						required: true
					},
					company_name: {
						required: false
					},
					nip: {
						required: false,
						maxlength: 10
					},
					city: {
						required: true
					},
					street_name: {
						required: true
					},
					house_number: {
						required: true
					},
					postcode: {
						required: true
					},
					telephone: {
						required: true,
						minlength: 9,
						number: true
					},
					email: {
						required: true,
						email: true
					},
					password: {
						required: true,
						minlength: 5
					},
					confirm_password: {
						required: true,
						minlength: 5,
						equalTo: "#password"
					}
				},
				messages: {
					first_name: {
						required: 'imię'
					},
					last_name: {
						required: 'nazwisko'
					},
					company_name: {
						required: 'wpisz nazwę firmy'
					},
					nip: {
						required: 'nip'
					},
					city: {
						required: 'miasto'
					},
					street_name: {
						required: 'ulica'
					},
					house_number: {
						required: 'numer domu'
					},
					postcode: {
						required: 'kod pocztowy'
					},
					telephone: {
						required: 'numer telefonu',
						minlength: 'wpisz właściwy nr tel',
						number: 'tylko cyfry'
					},
					email: {
						required: 'podaj adres e-mail',
						email: 'podaj właściwy format adresu e-mail'
					},
					password: {
						required: 'wprowadź hasło',
						minlength: 'hasło musi się składać z minimum 5 znaków'
					},
					confirm_password: {
						required: 'powtórz hasło',
						minlength: 'hasło musi się składać z minimum 5 znaków',
						equalTo: 'popraw hasło'
					}
				}
			});
		//	$("input[type=checkbox]").kCheck({
		//		path: 'js/kForm/'
		//	});
			$("#checkCompany").click(function() {
				if($(this).is(":checked")) {
					$("#first_name").rules("remove");
					$("#last_name").rules("remove");
					$("#company_name").rules("add", { required:true });
					$("#nip").rules("add", { required:true });
					$(this).parent().next().children().children().eq(0).hide();
					$(this).parent().next().children().children().eq(1).show();
					$(this).parent().next().children().children().eq(2).show();
				} else {
					$("#first_name").rules("add", { required:true });
					$("#last_name").rules("add", { required:true });
					$("#company_name").rules("remove");
					$("#nip").rules("remove");
					$(this).parent().next().children().children().eq(0).show();
					$(this).parent().next().children().children().eq(1).hide();
					$(this).parent().next().children().children().eq(2).hide();
				}
			});
		}
	});
}

function showSubPage(id) {
	$("#mainContent").html(loading);
	$.ajax({
		type: "POST",
		url: this.action,
		data: "showSubPage="+id,
		success: function(html) {
			$("#mainContent").html(html);
			contactForm();
		}
	});
}

function viewSwitch() {
	$('.itemList:first').before('<div class="viewSwitchHolder"><span class="v"></span><span class="h"></span></div>');
	$("#mainContent .viewSwitchHolder span.h").click(function() {
		$('#mainContent').find('.itemList').addClass('itemListLong');
	});
	$("#mainContent .viewSwitchHolder span.v").click(function() {
		$('#mainContent').find('.itemList').removeClass('itemListLong');
	});
}

function showItemsFrom(id) {
	$("#mainContent").html(loading);
	$.ajax({
		type: "POST",
		url: this.action,
		data: "showItemsFrom="+id,
		success: function(html) {
			$("#mainContent").html(html);
			// view changing icon
			viewSwitch();
			tooltip();
			addToCart();
			prepareLink();
		}
	});
}

function showNews() {
	$("#mainContent").html(loading);
	$.ajax({
		type: "POST",
		url: this.action,
		data: "show=news",
		success: function(html) {
			$("#mainContent").html(html);
		}
	});
}

function ajaxPost(data, container) {
	$(container).html(loading);
	$.ajax({
		type: "POST",
		url: this.action,
		data: data,
		success: function(html) {
			$(container).html(html);
		}
	});
}

function kSlide() {
	$('ul.kSlide').kSlide({
		width: 270,
		height: 'jump',
		root: 'http://www.fitelia.pl',
		phpthumb: 'http://www.fitelia.pl/included.php/phpThumb_1.7.9',
		phpthumbsize: 50,
		speed: 400,
		drop: 0,
		preloader: 'wczytywanie zdjęć...',
		transition: 'fade',
		callback: function() {
			$(".lightbox").fancybox();
		}
	});
}

function displayProduct(id) {
	$("#mainContent").html(loading);
	$.ajax({
		type: "POST",
		url: this.action,
		data: "showProduct="+id,
		success: function(html) {
			$("#mainContent").html(html);
			tooltip();
			kSlide();
			addToCart();
			prepareLink();
			$("form[name=ask]").validate({
				rules: {
					message: {
						required: true,
						minlength: 3
					},
					email: {
						required: true,
						email: true
					}
				},
				messages: {
					message: {
						required: '?',
						minlength: 'min 3'
					},
					email: {
						required: '?',
						email: '@'
					}
				}
			});
			$("form[name=ask]").ajaxForm({
				beforeSubmit: function(data, $form) {
					this.$form = $form;
					if($form.valid()) {
						var login_btn = $form.find("input[type=submit]").val();
						$form.find("input[type=submit]").attr({"disabled":"true"});
					} else
						return false;
				},
				success: function(data, $form) {
					var validator = this.$form.validate();
					validator.resetForm();
					this.$form.find("input[type=submit]").attr({"disabled":""});
				}
			});
		}
	});
}

function addToCart() {
	$("form[name=add_to_cart]").ajaxForm({
		beforeSubmit: function() {
			$('.cartBadge').append('<div class="loader"></div>');
		},
		success: function(data) {
			$('.cartBadge').html(data);
			$('.cartBadge').effect("shake", { times: 3, direction: 'up' }, 100);
			// showCart();
		}
	});
}

function emptyCart() {
	$.ajax({
		type: "POST",
		url: "index.php",
		data: "emptyCart=true",
		success: function(html) {
			$('.cartBadge').html(html);
			showCart();
		}
	});
}

function logout() {
	$.ajax({
		type: "POST",
		url: "index.php",
		data: "logout=true",
		success: function(html) {
			$(".loginHolder").html(html);
			ajaxPost('show=loginTab', '.loginTab');
			showCart();
		}
	});
}

function closeCartPanel() {
	$.unblockUI();
	$('.cartBadge').css({right: '0px'});
}

function loginForm() {
	validateLogin();
	$("form[name=login]").ajaxForm({
		beforeSubmit: function(data, $form) {
			this.$form = $form;
			if($form.valid()) {
				$form.find('input[type=submit]').attr({disabled: 'true'});
				var login_btn = $form.find("input[type=submit]").val();
				$form.find('input[type=submit]').css({backgroundColor: '#cccccc'});
			} else
				return false;
		},
		success: function(data, $form) {
			var validator = this.$form.validate();
			validator.resetForm();
			this.$form.find("input[type=submit]").attr({"disabled":""});
			$(".loginHolder").html(data);
			ajaxPost('show=loginTab', '.loginTab');
			showCart();
			loginForm();
		}
	});
}

function validateLogin() {
	$("form[name=login]").validate({
		rules: {
			email: {
				required: true,
				email: true
			},
			password: {
				required: true,
				minlength: 5
			}
		},
		messages: {
			email: {
				required: 'podaj swój adres e-mail',
				email: 'podaj poprawny e-mail'
			},
			password: {
				required: 'podaj hasło',
				minlength: 'minimum 5 znaków'
			}
		}
	});
}

function contactForm() {
	$("form[name=contactForm]").validate({
		rules: {
			category: {
				required: true
			},
			email: {
				required: true,
				email: true
			},
			message: {
				required: true
			}
		},
		messages: {
			category: {
				required: 'wybierz kategorię'
			},
			email: {
				required: 'podaj swój adres e-mail',
				email: 'podaj właściwy format adresu e-mail'
			},
			message: {
				required: 'wpisz swoją wiadomość'
			}
		}
	});
	$("form[name=contactForm]").ajaxForm({
		beforeSubmit: function(data, $form) {
			this.$form = $form;
			if($form.valid()) {
				$form.find("input[type=submit]").attr({"disabled": "true"}).addClass("disabled");
			} else
				return false;
		},
		success: function(data, $form) {
			this.$form.html(data);
		}
	});
}

function showCart() {
	$.ajax({
		type: "POST",
		url: this.action,
		data: "show=cart",
		success: function(html) {
			$(".cartHolder").html(html);
			shoppingCartSubmition();
			loginForm();
			// update badge quantity
			ajaxPost('show=badgeContent', '.cartBadge');
		}
	});
}

// old before 04/03/10
//function showCart() {
//	if ( $(".shHolder").length == 0 ) {
//		$("body").prepend('<div class=shHolder><table class=sh cellpadding=0 cellspacing=0><tr><td class=nw></td><td class=n></td><td class=ne></td></tr><tr><td class=w></td><td class=c>'+loading+'</td><td class=e></td></tr><tr><td class=sw></td><td class=s></td><td class=se></td></tr></table></div>');
//		$(".shHolder .ne, .shHolder .se, .shHolder .sw, .shHolder .nw").each(function(){
//			$(this).html("<div></div>");
//		});
//		$(".shHolder").fadeIn();
//	}
//	$.ajax({
//		type: "POST",
//		url: this.action,
//		data: "show=cart",
//		success: function(html) {
//			$(".shHolder .c").html(html);
//			$(".shHolder").draggable({
//				handle: 'h2',
//				stop: function() {
//					var top = $(this).css("top").substring(0, $(this).css("top").length-2);
//					var left = $(this).css("left").substring(0, $(this).css("left").length-2);
//					if(top < 0 || left < 0) {
//						if(left < 0) x = "0px";
//						else x = $(this).css("left");
//						if(top < 0) y = "0px";
//						else y = $(this).css("top");
//						$(this).animate({top: y, left: x});
//					}
//				}
//			});
//		}
//	});
//}

/* old function bouncingImage(element, xPos) {
	var element;
	var holderWidth = $(".floatCharHolder").width();
	var topPos = $(element).css("top");
	var xPos = Math.floor(Math.random()*(holderWidth-238));
	var zIndex = Math.floor(Math.random()*10);
	$(element).css({left: xPos, zIndex: zIndex});
	$(element).animate({top: "0px"}, {duration: 2000, easing: "easeInOutElastic", complete: function() {
		$(element).animate({top: topPos}, {duration: 5000, easing: "easeInOutElastic", complete: function() {
			setTimeout("bouncingImage('"+element+"', '"+xPos+"')", Math.floor(Math.random()*15000));
		}});
	}});
} */

function bouncingImage(element, xPos) {
	var holderWidth = $(".floatCharHolder").width();
	if($(element).css("top")) {
		var topPos = $(element).css("top").substring(0, $(element).css("top").length-2);
		var xPos = Math.floor(Math.random()*(holderWidth-238));
		var zIndex = Math.floor(Math.random()*10);
		$(element).animate({top: (parseInt(topPos) - 10)+"px"}, {duration: 4000, easing: "easeInOutElastic", complete: function() {
			$(element).animate({top: topPos}, {duration: 4000, easing: "easeInOutElastic", complete: function() {
				setTimeout("bouncingImage('"+element+"', '"+xPos+"')", Math.floor(Math.random()*5000));
			}});
		}});
	}
}

function randomBackgroundColor(element) {
	var color = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
	$(element).css({'backgroundColor': color});
	setTimeout("randomBackgroundColor('"+element+"')", 5000);
}

function timer(t) {
	$('#timer').html(t);
	if(t != 1) setTimeout(function() { t--; timer(t); }, 1000);
}

function animateBanner(array, delay, i) {
	if(!i) var i = 0;
	// timer('10');
	$('.mainBannerImage').find('td.c div').css({opacity: '0', backgroundImage: 'url('+array[i]+')'}).animate({opacity: '1'});
	//alert(array[i]);
	i++; if(i == array.length) var i = 0;
	setTimeout(function() { animateBanner(array, delay, i); }, delay);
}

function pageLoad(hash) {
	if(hash) {
		var string = hash.slice(1).split('_');
	} else {
		var string = splitHash();
	}
	if(string[0] == 'p' && string[1] > 0) {
		showSubPage(string[1]);
		menuClick('mainMenuItemId_'+string[1]);
		contactForm();
	} else if(string[0] == 'i' && string[1] > 0) {
		displayProduct(string[1]);
	} else if(string[0] == 'c' && string[1] > 0) {
		showItemsFrom(string[1]);
		menuClick('mainShopItemId_'+string[1]);
	}
	$.scrollTo('body', 800, {easing: 'easeInOutQuad'});
	return false;
}

function menuClick(id) {
	$('#'+id).parents('.mainMenu').parents().siblings().find('li').removeClass("selected").children(".hidden").hide();
	$('#'+id).next(".hidden").find('li').removeClass("selected").children(".hidden").hide();
	$('#'+id).parents('li').each(function() {
		$(this).siblings().removeClass("selected").children(".hidden").slideUp();
		$(this).addClass("selected").children(".hidden").slideDown();
	});
	if($('#'+id).next(".hidden").is(':hidden')) {
		$('#'+id).next(".hidden").slideDown(300);
	}
}

function tooltip() {
	$('.tooltip').tooltip({ 
		track: true,
		delay: 0,
		showURL: false,
		fade: 250
	});
}

function shopTabs() {
	var top_margin = 50; // was 10
	$('.mainHolder').animate({marginTop: top_margin+'px'}, 200).prev().show();
	$('.mainHolder').mouseover(function() {
		$(this).stop().animate({marginTop: top_margin+'px'}, 800, 'easeOutElastic');
	});
	$('.shopTabs .tab:not(.selected)').bind('mouseover', function() {
		$('.mainHolder').stop().animate({marginTop: '100px'}, 800, 'easeOutElastic');
	});
	if($('body.aqua').length == 1) {
		$('.shopTabs div.aqua').addClass('selected').unbind();
		$('.shopTabs div.fitelia').bind('click', function() {
			location.href = 'http://www.fitelia.pl';
			$('.mainHolder').prepend('<div style="position:absolute;padding:5px;">'+loading+'</div>').children('table').animate({opacity: 0});
		});
	} else {
		$('.shopTabs div.fitelia').addClass('selected').unbind();
		$('.shopTabs div.aqua').bind('click', function() {
			location.href = 'http://aqua.fitelia.pl';
			$('.mainHolder').prepend('<div style="position:absolute;padding:5px;">'+loading+'</div>').children('table').animate({opacity: 0});
		});
	}
}

function dialog(html) {
	$.blockUI({
		message: '<div class="close"></div><div class="loginHolder" style="padding: 10px;">'+html+'</div>',
		css: {
			left: '50%',
			marginLeft: '-200px',
			width: '400px',
			'-moz-border-radius': '5px',
			'-webkit-border-radius': '5px',
			height: '200',
			textAlign: 'left',
			cursor: 'default',
			backgroundColor: '#ffffff',
			border: 'none'
		},
		overlayCSS: {
			opacity: 0.9
		}
	});
	$('.blockOverlay, .close').css({cursor: 'pointer'}).click(function() {
		$.unblockUI();
	});
}

function pageOpen(id) {
	$.blockUI({
		message: '<div class="container" style="overflow:hidden;">'+loading+'</div>',
		css: {
			top: '50%',
			left: '50%',
			marginTop: '-250px',
			marginLeft: '-400px',
			width: '800px',
			height: '500px',
			'-moz-border-radius': '5px',
			'-webkit-border-radius': '5px',
			textAlign: 'left',
			cursor: 'default',
			backgroundColor: '#ffffff',
			border: 'none'
		},
		overlayCSS: {
			opacity: 0.9
		},
		onBlock: function() {
			$.ajax({
				type: 'POST',
				url: this.action,
				data: 'ajax=1&type=p&id='+id,
				success: function(html) {
					$('.blockPage').html(html);
					contactForm();
					$('.blockPage .container').jScrollPane();
					$('.blockOverlay, .close').css({cursor: 'pointer'}).click(function() {
						$.unblockUI({
							onUnblock: function() {
								$('.mainMenuHeader').parent('li').removeClass('selected');
							}
						});
					});
				}
			});
		}
	});
}

function shoppingCartSubmition() {
	$('form input.update').bind('blur', function() {
		$(this).parent('form').ajaxSubmit({
			beforeSubmit: function(data, $form) {
				this.$form = $form;
				$('form[name=update_cart]').find('input').attr({disabled: 'disabled'}).addClass('disabled');
			},
			success: function(data, $form) {
				showCart();
			}
		});
	});
	$("form[name=update_cart]").ajaxForm({
		beforeSubmit: function(data, $form) {
			this.$form = $form;
			$('form[name=update_cart]').find('input').attr({disabled: 'disabled'}).addClass('disabled');
			$form.find('input[type=submit]').attr({value: 'proszę czekać.'});
		},
		success: function(data) {
			showCart();
		}
	});
	$("form[name=place_order]").ajaxForm({
		beforeSubmit: function(data, $form) {
			this.$form = $form;
			if(confirm($form.find("input[type=submit]").attr("title"))) {
				$form.find('input[type=submit]').attr({value: 'wysyłanie... proszę czekać.', disabled: 'disabled'}).addClass('disabled');
			} else
				return false;
		},
		success: function(data) {
			$('.cartBadge').css({right: '0px'});
			$.unblockUI({
				onUnblock: function() {
					dialog('<div>Dziękujemy bardzo za złożone zamówienie. Proszę oczekiwać na wiadomość e-mail od naszego pracownika (maksymalnie 24h)</div><br /><div>Na podany przy rejestracji adres zostaną przesłane informacje potrzebne zarówno do zrealizowania płatności jak rownież szczegóły dotyczące transportu.</div>');
				}
			});
			emptyCart();
		}
	});
	$('form[name=carrier_select]').find('input').bind('change', function() {
		var el = $(this);
		$(this).parent().parent().parent().parent('form').ajaxSubmit({
			beforeSubmit: function(data, $form) {
				el.parent().append(' '+loading);
			},
			success: function(data, $form) {
				showCart();
			}
		});
	});
}

function loginPopUp() {
	$.blockUI({
		message: '<div class="close"></div><div class="loginHolder" style="padding: 10px;">'+loading+'</div>',
		css: {
			left: '50%',
			marginLeft: '-200px',
			width: '400px',
			'-moz-border-radius': '5px',
			'-webkit-border-radius': '5px',
			height: '200',
			textAlign: 'left',
			cursor: 'default',
			backgroundColor: '#ffffff',
			border: 'none'
		},
		overlayCSS: {
			opacity: 0.9
		}
	});
	$.ajax({
		type: "POST",
		url: this.action,
		data: "show=login",
		success: function(html) {
			$('.blockPage .loginHolder').html(html);
			loginForm();
		}
	});
	$('.blockOverlay, .close').css({cursor: 'pointer'}).click(function() {
		$.unblockUI();
	});
}

function shoppingCart() {
	var width = 500;
	$('.cartBadge').scrollFollow({offset: 50}).click(function() {
		$(this).append('<div class="loader"></div>');
		$.ajax({
			type: "POST",
			url: this.action,
			data: "show=cart",
			success: function(html) {
				$('.cartBadge .loader').remove();
				$.blockUI({
					message: '<div class="cartMargin cartHolder">'+html+'</div>',
					css: {
						top: '0px',
						left: 'auto',
						right: '0px',
						width: '0px',
						height: '100%',
						overflow: 'auto',
						textAlign: 'left',
						cursor: 'default',
						border: 'none'
					},
					overlayCSS: {
						opacity: 0.9
					},
					onBlock: function() {
						$(this).animate({width: width+'px'});
						$('.cartBadge').animate({right: (width-5)+'px'}, 'easeInOutElastic');
					}
				});
				shoppingCartSubmition();
				loginForm();
				$('.blockOverlay').css({cursor: 'pointer'}).click(function() {
					$.unblockUI();
					$('.cartBadge').css({right: '0px'});
				})
			}
		});
	});
}

function prepareLink() {
	$('.prepareLink').each(function() {
	var href = '#_'+$(this).attr('href');
		$(this).click(function() {
//			location.href = href;
//			return false;
		});
//		$(this).attr({href: href});
	});
}

$(document).ready(function() {
	// announce
	// $('body').prepend('<div class="announce"><img src="http://www.fitelia.pl/images/ico_warning.gif" align="absmiddle" /> Trwają prace konserwacyjne, w tym czasie wszelkie zamówienia prosimy składać e-mailowo kontakt@fitelia.pl. przepraszamy za utrudnienia.</div>');
	// add History and Back button
	pageLoad();
	$.historyInit(pageLoad);
	$("a[rel='history']").click(function() {
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');
		$.historyLoad(hash);
	});

	// $(".partnersHolder").html("<table cellpadding=0 cellspacing=0 class=mainFrame_v2 style=margin:auto><!--<tr><td class=mf_nw></td><td class=mf_n height=20></td><td class=mf_ne></td></tr>--><tr><td class=mf_w></td><td class=mf_c><div style=position:relative;padding:5px>"+$(".partnersHolder").html()+"</div></td><td class=mf_e></td></tr><tr><td class=mf_sw></td><td class=mf_s height=20></td><td class=mf_se></td></tr></table>");
	//$(".mainHolder").html("<table cellpadding=0 cellspacing=0 width=100% class=mainFrame><tr><td class=mf_n height=28></td></tr><tr><td class=mf_c><div style=position:relative;padding-bottom:20px;>"+$(".mainHolder").html()+"</div></td></tr><tr><td class=mf_s height=28></td></tr></table>").fadeIn("slow");

	// bouncing images
	$(".xxx").each(function(){
		var element = $(this).attr("id");
		setTimeout("bouncingImage('#"+element+"', '0')", Math.floor(Math.random()*15000));
	})
	// randomBackgroundColor('.floatCharHolder');

	/* CREATE BANNER ARRAY */
	var bArray = new Array();
	$(".bannerHolderAqua img.banner").each(function() {
		bArray.push($(this).attr('src'));
	});
	/* CREATE BANNER */
	$(".bannerHolderAqua img:eq(2)").each(function() {
		$(this).before("<div class=bigWrapper><table cellpadding=0 cellspacing=0 class='mainBannerImage'><tr><td class=nw></td><td class=n></td><td class=ne></td></tr><tr><td class=w></td><td class=c><div style='width: 500px; height: 330px; background-image: url("+$(this).attr('src')+")'></div></td><td class=e></td></tr><tr><td class=sw></td><td class=s></td><td class=se></td></tr></table></div>");
	});
	for(i=0;i<=2;i++) {
		$(".bannerHolderAqua").each(function() {
			// $(this).append("<div class=smallWrapper><table cellpadding=0 cellspacing=0><tr><td class=nw></td><td class=n></td><td class=ne></td></tr><tr><td class=w></td><td class=c><a href='#23' onclick=\"$('.mainBannerImage a').animate({width: '"+$(this).find('img:eq('+i+')').attr('width')+"px', height: '"+$(this).find('img:eq('+i+')').attr('height')+"px'}, 'slow', function() {$('.mainBannerImage a').css({backgroundImage: 'url("+$(this).find('img:eq('+i+')').attr('src')+")'})})\" style='background-image: url("+$(this).find('img:eq('+i+')').attr('src')+")'></a></td><td class=e></td></tr><tr><td class=sw></td><td class=s></td><td class=se></td></tr></table></div>");
			$(this).append("<div class=smallWrapper><table cellpadding=0 cellspacing=0><tr><td class=nw></td><td class=n></td><td class=ne></td></tr><tr><td class=w></td><td class=c><div style='background-image: url("+$(this).find('img:eq('+i+')').attr('src')+")'></div></td><td class=e></td></tr><tr><td class=sw></td><td class=s></td><td class=se></td></tr></table></div>");
		});
	}
	$(".bannerHolderAqua").html("<table cellpadding=0 cellspacing=0><tr><td>"+$('.bannerHolderAqua .smallWrapper:eq(0)').html()+"</td><td>"+$('.bannerHolderAqua .smallWrapper:eq(1)').html()+"</td></tr><tr><td>"+$('.bannerHolderAqua .smallWrapper:eq(2)').html()+"</td><td>"+$('.bannerHolderAqua .bigWrapper:eq(0)').html()+"</td><td valign=middle><div class=bannerNewsHolder>"+$('.bannerHolderAqua div.newsHolder:eq(0)').html()+"</div></td></tr></table>").fadeIn("slow");
	animateBanner(bArray, 10000);

	$(".e, .w").each(function(){
		$(this).html("<div style=width:10px;height:10px;overflow:hidden></div>");
	});

	$(".languageHolder a:last").click(function(){
		$(this).prev().slideToggle();
		$(".languageHolder span").toggle();
	});
	$("ul.mainMenu li a").click(function() {
		menuClick($(this).attr('id'));
	});

	// $('a').dwFadingLinks(); not workin on ie7

	$("#favCarousel").jcarousel({
		auto: 4,
		animation: 'slow',
		scroll: 1,
		wrap: 'last'
	});
	$(".jcarousel-container-horizontal").css({width: $(".middleColumn").width() - 100});

	$(".sortable").sortable({
		handle: '.listHeader',
		axis: 'y',
		start: function(event, ui) {
			$(ui.item).addClass('dragged');
		},
		stop: function(event, ui) {
			$(ui.item).removeClass('dragged');
		}
	});

	tooltip();
	shopTabs();
	shoppingCart();
	prepareLink();
	kSlide();
	addToCart();
	contactForm();
	viewSwitch();
});
