/*
29/01/2009
Maikii application JS file
author: Alessandro Chinazzo
*/

function switch_language(language) {
	var f = $('language_form');
	f.language_code.value = language;
	f.submit();
}

function setBrowserAddress(a) {
	//Element.extend(a);
	//window.location.href = "#" + a.pathname;
	window.location.assign("#" + a.pathname);
}

// IE6 fix: setto la classe 'hover'
function setHoverIE6(){
	$('#header #main-nav ul > li').hover(function(){
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
}

// Adatto le dimensioni delle voci del menu principale
function setMainNavItemWidth(){
	nav_item_width = Math.round(930 / $('#header #main-nav ul > li').size());
	$('#header #main-nav ul > li').each(function(){
		$(this).css("width", nav_item_width);
	});
	if ( nav_item_width*$('#header #main-nav ul li').size() > 930 ) {
		$('#header #main-nav ul > li:last').css('width', nav_item_width-(nav_item_width*$('#header #main-nav ul > li').size() - 930));
	}
	if ( nav_item_width*$('#header #main-nav ul > li').size() < 930 ) {
		$('#header #main-nav ul > li:last').css('width', nav_item_width+(930-nav_item_width*$('#header #main-nav ul > li').size()));
	}
	$('#header #main-nav ul').show();
}

// Adatto le dimensioni delle voci del sottomenu principale
function setMainNavSubItemWidth(){
	nav_item_width = Math.round(928 / $('#content #main-nav-sub ul > li').size());
	$('#content #main-nav-sub ul > li').each(function(){
		$(this).css("width", nav_item_width);
	});
	if ( nav_item_width*$('#content #main-nav-sub ul li').size() > 928 ) {
		$('#content #main-nav-sub ul > li:last').css('width', nav_item_width-(nav_item_width*$('#content #main-nav-sub ul > li').size() - 928));
	}
	if ( nav_item_width*$('#content #main-nav-sub ul > li').size() < 928 ) {
		$('#content #main-nav-sub ul > li:last').css('width', nav_item_width+(928-nav_item_width*$('#content #main-nav-sub ul > li').size()));
	}
	//$('#content #main-nav-sub ul').show();
}

// Aggiungo 2 div sopra e sotto il box per ottenere gli angoli arrotondati
function addBackgroundsToBoxLarge(){
	$boxtop = $(document.createElement("div")).attr("class","bg-box-dark-large-top");
	$('.box-dark-large').before($boxtop);
	$boxbottom = $(document.createElement("div")).attr("class","bg-box-dark-large-bottom");
	$('.box-dark-large').after($boxbottom);
}

function addBackgroundsToBoxSmall(){
	$boxtop = $(document.createElement("div")).attr("class","bg-box-dark-small-top");
	$('.box-dark-small').before($boxtop);
	$boxbottom = $(document.createElement("div")).attr("class","bg-box-dark-small-bottom");
	$('.box-dark-small').after($boxbottom);
}

function addPageSlide(){
	$('.container .cat a').click(function(){
		href = $(this).attr('href');
		id = $(this).attr('rel');
		$('#category').val(id);
		$('html,body').animate({
			scrollTop: 215
		}, 350, 'linear', setTimeout( "swapProducts('" + href + "', id)", 400));
		return false;
	});
}

function swapProducts(url, id){
	$('#product-list').animate({ opacity: 0 }, 350);
	$.ajax({
	  	type: "GET",
	  	url: url,
		dataType: "script",
		complete: function(data){
			pageTracker._trackPageview(url);
			$('#search form *').each(function(index, el){
				if (el.type == 'select-one'){
					$(el).val('0');
				}
				if (el.type == 'checkbox'){
					el.checked = false;
				}
			});
			$('#product-list').html(data.responseText);
			$('#product-list').animate({ opacity: 1 }, 350, function(){
				if(jQuery.browser.msie)
				   $('#product-list').css('background-color', '#fff');
			});
		}
	});
}

function addPackagingWindow(){
	$('.accessories li').click(function(){
		id = $(this).attr('rel');
		$('<div id="packaging" />').modal({
			position: ['315px',],
			onOpen: modalOpen,
			onShow: populateModalPackaging($(this), id), 
			onClose: modalClose
		});
		return false;
	});
}

function addQuoteWindow(){
	$('#btn-quote').click(function(){
		id = $(this).attr('rel');
		$('<div id="packaging" />').modal({
			position: ['30px',],
			onOpen: modalOpen,
			onShow: populateModalQuote($(this), id), 
			onClose: modalClose
		});
		return false;
	});
}

function addCallbackWindow(){
	$('li.callback').click(function(evt){
		position = ['145px', $(this).offset()['left'] - 219 + $(this).width()/2]
		$('<div id="packaging" />').modal({
			position: position,
			containerId: 'simplemodal-container-small',
			onOpen: modalOpenSimple,
			onShow: populateModalCallback, 
			onClose: modalCloseSimple
		});
		return false;
	});
}

function addNewsletterWindow(){
	$('li.newsletter').click(function(evt){
		position = ['145px', $(this).offset()['left'] - 219 + $(this).width()/2]
		$('<div id="packaging" />').modal({
			position: position,
			containerId: 'simplemodal-container-small',
			onOpen: modalOpenSimple,
			onShow: populateModalNewsletter, 
			onClose: modalCloseSimple
		});
		return false;
	});
}


function addQuoteListWindow(){
	$('.quote a').click(function(){
		$('<div id="packaging" />').modal({
			position: ['30px',],
			onOpen: modalOpen,
			onShow: populateModalQuoteList($(this)),
			onClose: modalClose
		});
		return false;
	});
}

function modalOpen(dialog) {
	dialog.overlay.fadeIn('normal', function () {
		dialog.container.fadeIn('normal', function () {
			dialog.data.hide().slideDown('fast');	 
		});
	});
}

function modalOpenSimple(dialog) {
	//dialog.overlay.fadeIn('fast'), function () {
		dialog.container.fadeIn('slow', function () {
			dialog.data.hide().slideDown('slow');	 
		});
	//});
}

function modalCloseSimple(dialog) {
	dialog.data.fadeOut(100, function () {
		dialog.container.fadeOut(100, function(){
			$.modal.close();
		});
	});
}

function modalClose(dialog) {
	dialog.data.fadeOut('fast', function () {
		dialog.container.fadeOut('fast', function () {
			dialog.overlay.fadeOut('slow', function () {
				$.modal.close();
			});
		});
	});
}

function populateModalQuote(dialog, id) {
	$.ajax({
	  	type: "GET",
	  	url: '/frontend/get_quote/' + id,
		dataType: "html",
		complete: function(html){
			$('#simplemodal-container').html(html.responseText);
			$('.modalCloseImg').bind('click.simplemodal', function(e) {
				e.preventDefault();
				$.modal.close();
			});
			$(".input_field").before("<span class=\"inputfield-left\"></span>");
			$(".input_field").after("<span class=\"inputfield-right\"></span>");
			addSubmitToQuote();
		}
	});
}

function populateModalCallback(dialog) {
	$.ajax({
	  	type: "GET",
	  	url: '/frontend/get_callback_form',
		dataType: "html",
		complete: function(html){
			$('#simplemodal-container-small').html(html.responseText);
			$('.modalCloseImg').bind('click.simplemodal', function(e) {
				e.preventDefault();
				$.modal.close();
			});
			$(".input_field").before("<span class=\"inputfield-left\"></span>");
			$(".input_field").after("<span class=\"inputfield-right\"></span>");
			addSubmitToCallback();
		}
	});
}

function populateModalNewsletter(dialog) {
	$.ajax({
	  	type: "GET",
	  	url: '/frontend/get_newsletter_form',
		dataType: "html",
		complete: function(html){
			$('#simplemodal-container-small').html(html.responseText);
			$('.modalCloseImg').bind('click.simplemodal', function(e) {
				e.preventDefault();
				$.modal.close();
			});
			$(".input_field").before("<span class=\"inputfield-left\"></span>");
			$(".input_field").after("<span class=\"inputfield-right\"></span>");
			addSubmitToNewsletter();
		}
	});
}

function populateModalQuoteList(dialog) {
	$.ajax({
	  	type: "GET",
	  	url: '/frontend/get_quote_list',
		dataType: "html",
		complete: function(html){
			$('#simplemodal-container').html(html.responseText);
			$('.modalCloseImg').bind('click.simplemodal', function(e) {
				e.preventDefault();
				$.modal.close();
			});
			$('.edit_quote').bind('click', function(e) {
				editQuote( $(this).attr('rel') );
			});
			$('.remove_from_quote').bind('click', function(e) {
				removeFromQuoteList( $(this).attr('rel') );
			});
			addGoToForm();
			addGoToCatalogue();
		}
	});
}

function removeFromQuoteList(id){
	$.ajax({
	  	type: "GET",
	  	url: '/frontend/remove_from_quote/' + id,
		dataType: "html",
		complete: function(html){
			$('#simplemodal-container').html(html.responseText);
			$('.modalCloseImg').bind('click.simplemodal', function(e) {
				e.preventDefault();
				$.modal.close();
			});
			$('.remove_from_quote').bind('click', function(e) {
				removeFromQuoteList( $(this).attr('rel') );
			});
			addGoToForm();
			addGoToCatalogue();
			$.ajax({
			  	type: "GET",
			  	url: '/frontend/get_quote_size',
				dataType: "html",
				complete: function(data){
					if ( data.responseText == 0 ){
						$('.counter').remove();
					} else {
						$('.counter').html(data.responseText);
					}
				}
			});
		}
	});
}

function populateModalPackaging(dialog, id) {
	$.ajax({
	  	type: "GET",
	  	url: '/frontend/get_packaging/' + id,
		dataType: "html",
		complete: function(html){
			$('#simplemodal-container').html(html.responseText);
			$('.modalCloseImg').bind('click.simplemodal', function(e) {
				e.preventDefault();
				$.modal.close();
			});
		}
	});
}

function addProductsFilter(){
	dataToSend = '';
	
	$("#search form *").each(function(index, el){
		
		if ( el.type == 'select-one' ) {
			$(el).bind('change', function(){
				category = 'category=' + $('#category').val() + '&';
				$("#search form").bind('submit', function(evt){
					$('#product-list').animate({ opacity: 0 }, 350);
					$.ajax({
						type: "GET",
						url: "/frontend/get_products_by_filters",
						dataType: "html",
						data: category + dataToSend,
						complete: function(data){
							$('#product-list').html(data.responseText).animate({ opacity: 1 }, 350, function(){
								if(jQuery.browser.msie){
								   $('#product-list').css('background-color', '#fff');
								}
							});
						}
					});
					$("#search form").unbind('submit');
					return false;
				});
				$("#search form *").each(function(index, el){
					if (el.type == 'select-one'){
						dataToSend += $(el).attr('name') + '=' + $(el).val() + '&';
					}
					if (el.type == 'checkbox' && el.checked){
						dataToSend += $(el).attr('name') + '=' + $(el).val() + '&';
					}
				});
				$("#search form").submit();
				dataToSend = '';
			});
		}
		
		if ( el.type == 'checkbox' ) {
			//$(el).prettyCheckboxes();
			//$('label[for="'+$(this).attr('id')+'"]')
			$(el).click(function(){
				category = 'category=' + $('#category').val() + '&';
				$("#search form").bind('submit', function(evt){
					$('#product-list').animate({ opacity: 0 }, 350);
					$.ajax({
						type: "GET",
						url: "/frontend/get_products_by_filters",
						dataType: "html",
						data: category + dataToSend,
						complete: function(data){
							$('#product-list').html(data.responseText).animate({ opacity: 1 }, 350, function(){
								if(jQuery.browser.msie){
								   $('#product-list').css('background-color', '#fff');
								}
							});
						}
					});
					$("#search form").unbind('submit');
					return false;
				});
				$("#search form *").each(function(index, el){
					if (el.type == 'select-one'){
						dataToSend += $(el).attr('name') + '=' + $(el).val() + '&';
					}
					if (el.type == 'checkbox' && el.checked){
						dataToSend += $(el).attr('name') + '=' + $(el).val() + '&';
					}
				});
				$("#search form").submit();
				dataToSend = '';
			});
		}
		
	});
	
}

function addSubmitToCallback(){
	$("form.callback").bind('submit', function(evt){
		sendable = true;
		$("form.callback *").each(function(index, el) {
			if ( el.type == 'text' || el.type == 'checkbox' || el.type == 'textarea' || el.type == 'select-one' ) {
				if ($(el).attr('rel') == 'required' && $(el).val() == '') {
					$('#simplemodal-container-small .error').css('display', 'block');
					sendable = false;
					return false;
				}
				if ($(el).attr('rel') == 'required_email') {
					if ( !$(el).val().match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/) || $(el).val() == '' ) {
						$('#simplemodal-container-small .error-mail').css('display', 'block');
						sendable = false;
						return false;
					}
				}
				if ($(el).attr('rel') == 'required_privacy') {
					if ( !el.checked ) {
						$('#simplemodal-container-small .error-privacy').css('display', 'block');
						sendable = false;
						return false;
					}
				}
			}
		});
		if (sendable == true) {
			dataToSend = '';
			$("form.callback *").each(function(index, el){
				if (el.type == 'select-one' || el.type == 'text' || el.type == 'hidden' || el.type == 'textarea' || (el.type == 'checkbox' && el.checked)){
					dataToSend += $(el).attr('name') + '=' + $(el).val() + '&';
				}
			});
			$.ajax({
	  			type: "POST",
	  			url: '/frontend/send_callback',
				data: dataToSend,
				dataType: "html",
				complete: function(data){
					$('#simplemodal-container-small').html(data.responseText);
					$('.modalCloseImg').bind('click.simplemodal', function(e) {
						e.preventDefault();
						$.modal.close();
					});
				}
			});
		}
		return false;
	});
}

function addSubmitToNewsletter(){
	$("form.newsletter").bind('submit', function(evt){
		sendable = true;
		$("form.newsletter *").each(function(index, el) {
			if ( el.type == 'text' || el.type == 'checkbox' || el.type == 'textarea' || el.type == 'select-one' ) {
				if ($(el).attr('rel') == 'required' && $(el).val() == '') {
					$('#simplemodal-container-small .error').css('display', 'block');
					sendable = false;
					return false;
				}
				if ($(el).attr('rel') == 'required_email') {
					if ( !$(el).val().match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/) || $(el).val() == '' ) {
						$('#simplemodal-container-small .error-mail').css('display', 'block');
						sendable = false;
						return false;
					}
				}
				if ($(el).attr('rel') == 'required_privacy') {
					if ( !el.checked ) {
						$('#simplemodal-container-small .error-privacy').css('display', 'block');
						sendable = false;
						return false;
					}
				}
			}
		});
		
		numChecked = 0;
		$('form.newsletter').find('input[type=checkbox]').each(function(){
			if ( $(this).attr('name') == 'checkbox_newsletter[]' ) {
				if ( this.checked ) {
					numChecked++;
				}
			}
		});
		
		if ( numChecked == 0 ) {
			$('#simplemodal-container-small .error-newsletter').css('display', 'block');
			sendable = false;
		}
		
		if (sendable == true) {
			dataToSend = '';
			$("form.newsletter *").each(function(index, el){
				if (el.type == 'select-one' || el.type == 'text' || el.type == 'hidden' || el.type == 'textarea' || (el.type == 'checkbox' && el.checked)){
					dataToSend += $(el).attr('name') + '=' + $(el).val() + '&';
				}
			});
			$.ajax({
	  			type: "POST",
	  			url: '/frontend/send_newsletter',
				data: dataToSend,
				dataType: "html",
				complete: function(data){
					$('#simplemodal-container-small').html(data.responseText);
					$('.modalCloseImg').bind('click.simplemodal', function(e) {
						e.preventDefault();
						$.modal.close();
					});
				}
			});
		}
		return false;
	});
}

function addSubmitToQuote(){
	$("form.add_to_quote").bind('submit', function(evt){
		sendable = true;
		$("form.add_to_quote *").each(function(index, el){
			if ($(el).attr('rel') == 'required' && $(el).val() == '') {
				$('.error').css('display', 'block');
				sendable = false;
				return false;
			} 
		});
		if ( sendable == true ) {
		dataToSend = '';
		$("form.add_to_quote *").each(function(index, el){
			if (el.type == 'select-one' || el.type == 'text' || el.type == 'hidden' || el.type == 'textarea' || (el.type == 'checkbox' && el.checked)){
				dataToSend += $(el).attr('name') + '=' + $(el).val() + '&';
			}
		});
		$.ajax({
			type: "POST",
			url: "/frontend/add_to_quote",
			dataType: "html",
			data: dataToSend,
			complete: function(data){
				$.ajax({
					type: "GET",
					url: "/frontend/get_quote_list",
					dataType: "html",
					//data: dataToSend,
					complete: function(html){
						$('#simplemodal-container').html(html.responseText);
						$('.modalCloseImg').bind('click.simplemodal', function(e) {
							e.preventDefault();
							$.modal.close();
						});
						$('.edit_quote').bind('click', function(e) {
							editQuote( $(this).attr('rel') );
						});
						$('.remove_from_quote').bind('click', function(e) {
							removeFromQuoteList( $(this).attr('rel') );
						});
						addGoToForm();
						addGoToCatalogue();
						$.ajax({
						  	type: "GET",
						  	url: '/frontend/get_quote_size',
							dataType: "html",
							complete: function(data){
								if ( $('.counter').length > 0 ){
									$('.counter').html(data.responseText);
								} else {
									$counter = $(document.createElement("span")).attr("class","counter");
									$counter.html(data.responseText);
									$('.quote').append( $counter );
								}
							}
						});
					}
				});
			}
		});}
		
		return false;
	});
}

function addSaveToQuote(){
	$("form.edit_quote").bind('submit', function(evt){
		sendable = true;
		$("form.edit_quote *").each(function(index, el){
			if ($(el).attr('rel') == 'required' && $(el).val() == '') {
				$('.error').css('display', 'block');
				sendable = false;
				return false;
			} 
		});
		if (sendable == true) {
		dataToSend = '';
		$("form.edit_quote *").each(function(index, el){
			if (el.type == 'select-one' || el.type == 'text' || el.type == 'hidden' || el.type == 'textarea' || (el.type == 'checkbox' && el.checked)){
				dataToSend += $(el).attr('name') + '=' + $(el).val() + '&';
			}
		});
		$.ajax({
			type: "POST",
			url: "/frontend/edit_quote",
			dataType: "html",
			data: dataToSend,
			complete: function(data){
				$.ajax({
					type: "GET",
					url: "/frontend/get_quote_list",
					dataType: "html",
					complete: function(html){
						$('#simplemodal-container').html(html.responseText);
						$('.modalCloseImg').bind('click.simplemodal', function(e) {
							e.preventDefault();
							$.modal.close();
						});
						$('.edit_quote').bind('click', function(e) {
							editQuote( $(this).attr('rel') );
						});
						$('.remove_from_quote').bind('click', function(e) {
							removeFromQuoteList( $(this).attr('rel') );
						});
						addGoToForm();
						addGoToCatalogue();
						$.ajax({
						  	type: "GET",
						  	url: '/frontend/get_quote_size',
							dataType: "html",
							complete: function(data){
								if ( $('.counter').length > 0 ){
									$('.counter').html(data.responseText);
								} else {
									$counter = $(document.createElement("span")).attr("class","counter");
									$counter.html(data.responseText);
									$('.quote').append( $counter );
								}
							}
						});
					}
				});
			}
		});}
		
		return false;
	});
}

function addGoToForm(){
	$("button.go_to_form").bind('click', function(evt){
		$.ajax({
	  		type: "GET",
	  		url: '/frontend/get_quote_form',
			dataType: "html",
			complete: function(html){
				$('#simplemodal-container').html(html.responseText);
				$('.modalCloseImg').bind('click.simplemodal', function(e) {
					e.preventDefault();
					$.modal.close();
				});
				$(".input_field").before("<span class=\"inputfield-left\"></span>");
				$(".input_field").after("<span class=\"inputfield-right\"></span>");
				addSendQuote();
				addBackToList();
			}
		});
	});
}

function addGoToCatalogue(){
	$("button.go_to_catalogue").bind('click', function(){
		window.location = $(this).attr('rel');
	});
}

function addBackToList(){
	$(".back_to_list").bind('click', function(evt){
		$.ajax({
	  		type: "GET",
	  		url: '/frontend/get_quote_list',
			dataType: "html",
			complete: function(html){
				$('#simplemodal-container').html(html.responseText);
				$('.modalCloseImg').bind('click.simplemodal', function(e) {
					e.preventDefault();
					$.modal.close();
				});
				$('.edit_quote').bind('click', function(e) {
					editQuote( $(this).attr('rel') );
				});
				$('.remove_from_quote').bind('click', function(e) {
					removeFromQuoteList( $(this).attr('rel') );
				});
				addGoToForm();
				addGoToCatalogue();
			}
		});
	});
}

function addSendQuote(){
	$("form.quote_to_send").bind('submit', function(evt){
		sendable = true;
		$("form.quote_to_send *").each(function(index, el) {
			if ( el.type == 'text' || el.type == 'checkbox' || el.type == 'textarea' || el.type == 'select-one' ) {
				if ($(el).attr('rel') == 'required' && $(el).val() == '') {
					$('.error').css('display', 'block');
					sendable = false;
					return false;
				}
				if ($(el).attr('rel') == 'required_email') {
					if ( !$(el).val().match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/) || $(el).val() == '' ) {
						$('.error-mail').css('display', 'block');
						sendable = false;
						return false;
					}
				}
				if ($(el).attr('rel') == 'required_privacy') {
					if ( !el.checked ) {
						$('.error-privacy').css('display', 'block');
						sendable = false;
						return false;
					}
				}
			}
		});
		if (sendable == true) {
			dataToSend = '';
			$("form.quote_to_send *").each(function(index, el){
				if (el.type == 'select-one' || el.type == 'text' || el.type == 'hidden' || el.type == 'textarea' || (el.type == 'checkbox' && el.checked)){
					dataToSend += $(el).attr('name') + '=' + $(el).val() + '&';
				}
			});
			$.ajax({
	  			type: "POST",
	  			url: '/frontend/send_quote',
				data: dataToSend,
				dataType: "html",
				complete: function(data){
					$('#simplemodal-container').html(data.responseText);
					$('.modalCloseImg').bind('click.simplemodal', function(e) {
						e.preventDefault();
						$.modal.close();
					});
					$('.counter').remove();
				}
			});
		}
		return false;
	});
}

function editQuote(id){
	$.ajax({
	  	type: "GET",
	  	url: '/frontend/get_quote_to_edit/' + id,
		dataType: "html",
		complete: function(html){
			$('#simplemodal-container').html(html.responseText);
			$('.modalCloseImg').bind('click.simplemodal', function(e) {
				e.preventDefault();
				$.modal.close();
			});
			$(".input_field").before("<span class=\"inputfield-left\"></span>");
			$(".input_field").after("<span class=\"inputfield-right\"></span>");
			$(".input_field").css('behaviour', 'url(\'/stylesheets/iepngfix.htc\')');
			addSaveToQuote();
		}
	});
}

function addProductZoom(){
	$('.zoom').click(function(){
		
		$imgClicked = $(this);
		$loader = $('<div id="loader" />');
		$loader.hide();
		$('body').append($loader);
		$loader.css({
			opacity: 0.5,
			width: $imgClicked.width(),
			height: $imgClicked.height(),
			top: $imgClicked.offset().top,
			left: $imgClicked.offset().left
		});
		$loader.show();
		
		img = new Image();
		$imgToOpen = $(img).attr("class","popup");
		
		$imgToOpen.load(function(){
			$loader.hide();
			$loader.remove();
			$('#fade').animate({
				opacity: 0
			}, 300);
			$(this).hide();
			$('body').append($(this));
			targetWidth = $(this).width();
			targetHeight = $(this).height();
			$(this).css({
				position: 'absolute',
				width: $imgClicked.width(),
				height: $imgClicked.height(),
				top: $imgClicked.offset().top,
				left: $imgClicked.offset().left,
				border: '1px solid #d1d1d1',
				zIndex: '20000',
				cursor: 'pointer'
			});
			
			contentHeightDefault = $('#content').height();
			contentHeight = ((targetHeight+125) > $('#content').height()) ? targetHeight + 125 : $('#content').height();
			
			$('#content').animate({
				height: contentHeight
			}, 300);
			$(this).show().animate({
					top: '324px',
					left: $('#product').offset().left,
					width: targetWidth,
					height: targetHeight
				}, 750);
		}).attr('src', $imgClicked.attr('rel')).click(function(){
			$(this).show().animate({
					top: $imgClicked.offset().top,
					left: $imgClicked.offset().left,
					width: $imgClicked.width(),
					height: $imgClicked.height()
				}, 500, function(){
					$('#fade').animate({
						opacity: 1
					}, 300, function(){
						if (jQuery.browser.msie) { 
							this.style.removeAttribute('filter');
						}
					});
					$('#content').animate({
						height: contentHeightDefault
					}, 300);
					$(this).remove();
				});
		});
			
		return false;
		
	});
}

$(document).ready(function(){
	
	$bg = $(document.createElement("div")).attr("id","bg-top-content");
	$('#content').wrap($bg);
	
	addCallbackWindow();
	addNewsletterWindow();
	setMainNavItemWidth();
	setMainNavSubItemWidth();
	setHoverIE6();
	addBackgroundsToBoxLarge();
	addBackgroundsToBoxSmall();
	//addPageSlide();
	addProductsFilter();
	addPackagingWindow();
	addQuoteWindow();
	addQuoteListWindow()
	addProductZoom();
	
	
	
	$(".input_field").before("<span class=\"inputfield-left\"></span>");
	$(".input_field").after("<span class=\"inputfield-right\"></span>");
	
	$(".input_field_grey").before("<span class=\"inputfield-grey-left\"></span>");
	$(".input_field_grey").after("<span class=\"inputfield-grey-right\"></span>");
	
});

