/* * main.js 1.2 * By Komunikado (http://komunikado.dk) * Copyright (c) 2011 */jQuery(document).ready(function($) {		$('.b-pop_up').delegate('a.b-close_pop, .close_button', 'click', function() {		// sets close links and buttons for popup windows.		// a simple click event is not enough as popup content is loaded dynamicly		$(this).parents('.b-pop_up').fadeOut(300);		return false;	})		$("a[href='#']").click(function(e) {		// javascript links should not be allowed to put that awful # in the url		// do not use return false as it prevents other js events to fire		e.preventDefault();	});		$("a.back-link").click(function() {		history.back();		return false;	});  	/* Newsletter form */	/* If browser does not support the placeholder attribute, use js to switch helper text. In case of noscript, the input will be empty */	if (!("placeholder" in document.createElement("input"))) {		$("#newsletter-validate-detail input[name='email']").focus(function() {					if( $(this).val() == $(this).attr('title') ) {				$(this).val( '' );			}		}).blur(function() {			if( $(this).val() == '' ) {				$(this).val( $(this).attr('title') );			}		}).val(function() {			return $(this).attr('title');		});	}	/* Submit the form with AJAX...probably need to fix some PHP that wants to redirect the user after successful subscription */	$("form#newsletter-validate-detail").submit(function() {		// PARAMETERS : Load the wanted parameters from the form		var mail = $("input[name='email']", this).val();		// VALIDATION : Validate the parameters		// test for blank input		if( mail != '' ) {			// test for type=email support. if supported there's no need to validate as the browser does it for you			var i = document.createElement("input");			i.setAttribute("type", "email");			if( i.type !== "email" && mail.indexOf('@', 1) == -1 ) {				// type=email not supported and mail invalid				// set some error styling to the input...should be moved to method using stylesheet and toggleClass				$("#newsletter-validate-detail input[name='email']", this).css('border','1px solid red').focus();				return false;			}		} else {			// input is empty, set error style			$("#newsletter-validate-detail input[name='email']", this).css('border','1px solid red').focus();			return false;		}		// mail is fine and can be submitted		// remove error styling from form...move to stylesheet		$("#newsletter-validate-detail input[name='email']", this).css('border','1px solid transparent');		params = $(this).serialize();		$notify = $(".b-notification_popup");		// AJAX SUBMIT		$.post("/en/cms/ajax/newsletter/", params, function( data ) {			data = typeof data == 'object' ? data : jQuery.parseJSON(data);			// CALLBACK			$notify.show();			$notify.find('.popupwrapper div').html( data.message );			$notify.find('.popupwrapper p').html( data.submessage );			setTimeout(function() {				$notify.hide(200);			}, 4000);		}, 'json');		return false;	});			/* AJAX Cart & Wishlist */	$('body').delegate('.ajaxurl', 'click', function() {		var url = $(this).attr('href');		$notify = jQuery(".b-notification_popup");		$loader = jQuery(".b-loader_popup");		if( url != '' && url != '#' ) {			$loader.show();			var params = $(this).parents("form").serialize();			/*$.post(url, params, function( data ) {				$loader.hide();				if( data.cartUpdate ) {					$("#basketitemcount").html( '('+data.cartUpdate+')' );					$('a.basket:not(.full)').addClass('full');				}				$notify.show();				$notify.find(".popupwrapper div").html( data.message );				$notify.find(".popupwrapper p").html( data.submessage );				setTimeout(function() {					$notify.hide(200);				}, 1000);			}, 'json');*/			$.ajax({				url : url,				data : params,				dataType : 'json',				type : "POST",				error : function() {					$loader.hide();				},				success : function( data ) {					data = typeof data == 'object' ? data : jQuery.parseJSON(data);					$loader.hide();					if( data.cartUpdate ) {						$("#basketitemcount").html( '('+data.cartUpdate+')' );						$('a.basket:not(.full)').addClass('full');					}					$notify.show();					$notify.find(".popupwrapper div").html( data.message );					$notify.find(".popupwrapper p").html( data.submessage );					setTimeout(function() {						$notify.hide(200);					}, 4000);				}			})		}		return false;	});		/* Product popup */	$("body").delegate('.ajaxproduct', 'click', function() {		var url = $(this).attr('href').replace("#","");		$(".b-loader_popup").show();		$(".b-icon_popup .popupwrapper").load(url, function() {			$(".b-loader_popup").hide();			$(this).parent().show();		});		return false;	});		/* Thumbnail switcher */	/* Gallery */	$("body").delegate('.image_thumbnail img', 'click', function() {		var src = $(this).attr('src');		$(".product .product_image").attr("src", src);		return false;	});	/* Configurable products */	$(".options_holder div.option_color").die('click').live('click', function() {		$(".options_holder div.active").removeClass('active');		$(this).addClass('active');				/* Switch image */		var src = $("label", this).attr('data-image');		$(".product_image").attr("src", src);				/* Switch gallery */		var gallery = $("input", this).data('gallery');		gal = gallery.split(',');		$gallery = jQuery(".gallery .mini_preview").html('');		for(var i in gal) {			if( typeof gal[i] == "string" ) {				var extension = gal[i].substr( (gal[i].lastIndexOf('.') +1) ).toUpperCase();				if( extension == "PNG" || extension == "JPG" || extension == "GIF" || extension == "JPEG"  ) {					$gallery.append('<li><a href="#" class="image_thumbnail"><img src="'+gal[i]+'" alt="" height="104" width="78"  /></a></li>');				}			}		}				/* Switch qty */		var qty = $("label", this).data('qty');		if(qty*1 > 0) {			jQuery("a.b-icon_preorder").removeClass('b-icon_preorder').addClass('b-icon_market')			.html('<em></em>'+ $("label", this).data('qtylabel'));		} else {			jQuery("a.b-icon_market").removeClass('b-icon_market').addClass('b-icon_preorder')			.html('<em></em>'+ $("label", this).data('qtylabel'));		}				/* show length dropdown */		var ident = $("input", this).val();		$('.options_holder select').hide();		$('.options_holder select[name="select_'+ident+'"]').show().click(function() {			// on click change value			$('.options_holder input[name="super_attribute[140]"]').val($('.options_holder select[name="select_'+ident+'"]').val());		});		$('.options_holder input[name="super_attribute[140]"]').val($('.options_holder select[name="select_'+ident+'"]').val());	});		/* AddThis popup */	$(".b-icon_share").live('click', function() {		$(".b-addthis_popup").show();		return false;	});		/* Triangles */	$('.category map').bind('mouseover', function() {		$('.category.active').removeClass('active').addClass('wasactive');		$(this).parent().find('.color').stop(true,true).fadeIn();	})	.bind('mouseout', function() {		$('.category.wasactive').removeClass('wasactive').addClass('active');		$found = $(this).parent().find('.color');		if (!$found.hasClass('active')) {			$found.stop(true, true).fadeOut();		}	});	/*.click(function() {		var theme = $(this).attr('name').substr(0, 10);		switch( theme ) {			case 'greyHealth':				gotoPage( 1 );			break;			case 'greyCareer':				gotoPage( 2 );			break;			case 'greySportM':				gotoPage( 3 );			break;			case 'greyTravel':				gotoPage( 4 );			break;		}		console.log( theme );		// Should hide all colored triangles when switching page so that they are not shown next time that triangle is shown.....but it does not work		$(this).parents('.slidemetoheaven').find('.color').fadeOut();		return false;	});*/	}); /* end .ready() */
