if(logicbox === undefined) var logicbox = {};
(function($) {
	
	$.fn.simplyShadow = function() {
		return this.each(function() {
			$(this).addClass('dropshadow-vert-right').wrap('<div class="dropshadow"></div>').before('<div class="dropshadow-corner-rb"></div><div class="dropshadow-end-bl"></div><div class="dropshadow-horz-bottom"></div>');
			$(this).parent().find('.dropshadow-horz-bottom').css('width',$(this).find('li').outerWidth()-6 + 'px');
			$(this).parent().parent().hide().css('visibility','visible');
		});
	}
	
	$.fn.simplyDropdown = function() {
		return this.each(function() {
			//vertical align
			$(this).find('span').css('margin-top','-' + $(this).find('span').outerHeight()/2 + 'px');
			if ($(this).find('a').length) {
				$(this).hover(
					function() { $(this).css('background-color','#FFF'); $("div.subnav",this).show();},
					function() { $(this).css('background-color',''); $("div.subnav",this).hide();}
				);
			}
		});
	}
	
	var regionSelector = function() {
		
		var timeout = null,
			hideLang = function() {
				$('#lang a').show();
				$("#lang-selector").hide();
			};
		
		$('#lang a').click(function() {
			$(this).hide();
			$("#lang-selector").show();
			return false;
		});
		
		$("#lang-selector a").hover(
			function() { clearTimeout(timeout);},
			function() { timeout = setTimeout(hideLang,100);}
		);
	}
	
	$.fn.products = function () {
		return this.each(function() {
								  
			
								  
			var self = this,
				timeout,
				active = false;
			
			var funcIn = function() {
				active = true;
				if (!$.browser.msie) {
					$(self).find('img').fadeTo(500,0.6);
				}
				$(self).find('p.title').animate({marginTop:"-20px"},500,
					function() {
						if (active) {
							!$.browser.msie ? $(self).find('.subcat-overlay').fadeIn() : $(self).find('.subcat-overlay').show();
						}
					}
				);
			};
			var	funcOut = function() {
				!$.browser.msie ? $(self).find('.subcat-overlay').fadeOut() : $(self).find('.subcat-overlay').hide();
				
				$(self).find('p.title').animate({marginTop:0},500);
				if (!$.browser.msie) {
					$(self).find('img').fadeTo(500,1);
				}
				active = false;
			};
								  
			$(this).find('.subcat-overlay-inner').addClass('dropshadow-vert-right').wrap('<div class="dropshadow"></div>').before('<div class="dropshadow-corner-rb"></div><div class="dropshadow-end-bl"></div><div class="dropshadow-horz-bottom"></div>');
			$(this).find('.subcat-overlay-inner').parent().find('.dropshadow-horz-bottom').css('width',$(this).find('.products').outerWidth()-4 + 'px');
			$(this).find('.subcat-overlay').hide().css('visibility','visible');
				
			$(this).hover(function() {
				if (active) {
					clearTimeout(timeout);
				} else {
					
					funcIn();
				}
				//$(this).find('.subcat-overlay').show();					   
			},function() {
				timeout = setTimeout(funcOut,250);
				
			});
			
			$(this).find('.subcat-overlay').mouseover(function() {
				clearTimeout(timeout);
			});
			
		});
	};
	
	$.fn.preview = function() {
	
		var index = 0,
			zoomIndex = 0,
			draggable = null,
			defaultColour = $(this).attr('class').match(/[0-9]{2}-[0-9]{3}-[0-9A-Z]{2}$/)[0],
			currentColour = defaultColour,
			loadedColours = [],
			imagePath = '/images/imprint2010/product_shots_cached/',
			imageFilenames = ['_RGB_front_LR.jpg','_RGB_front_HR.jpg','_Back_RGB_back_LR.jpg','_Back_RGB_back_HR.jpg','_RGB_tb_front.jpg','_Back_RGB_tb_back.jpg'],
			self = this;
			
		$(this).prepend('<div class="containment-helper"></div>');
		
		//remove draggable instance and reset position
		var destroyDraggable = function(resetPos) {
			if (draggable!==null) {
				$("#preview-image div:eq("+index+") img").eq(1).draggable('destroy');
				if (resetPos) {
					$("#preview-image div:eq("+index+") img").eq(1).css({top:0,left:0})//.css({top:"-180px",left:"-152px"});
				}
				draggable=null;
			}
		};
		
		//clear previous zoom
		var clearZoom = function() {
			$(self).find('.image-zoom').removeClass('image-zoom-out');
			$("#preview-image div:eq("+index+") img").hide().eq(0).show();
			destroyDraggable(true);
		};
		
		//stop dragging of non-draggable images (firefox)
		$(this).find("#preview-image div").each(function(){
			$(this).find("img").eq(0).mousedown(function(){return false;});
		});
		
		//thumbnail selection
		$(this).find("#preview-thumbs .preview-thumb").click(function() {
			//set preview
			index = $("#preview-thumbs .preview-thumb").index(this);
			$("#preview-image div").hide().eq(index).show();
			
			
			clearZoom();
		});
		
		//zoom in/out - init draggable on large (2nd) image
		$(this).find('.image-zoom').click(function() {
			$(this).toggleClass('image-zoom-out');
			
			zoomIndex = $(this).hasClass('image-zoom-out') ? 1 : 0;
			$("#preview-image div:eq("+index+") img").hide().eq(zoomIndex).show();
			
			if (zoomIndex === 1) {
				
				draggable = $("#preview-image div:eq("+index+") img").eq(1).css({cursor:'move'}).draggable({containment:$("#preview .containment-helper"),cursor:'move'});
				
			} else {
				destroyDraggable(false);
			}
			
		});
		
		//colour selector
		$('.colour-container .colour').click(function() {
			var selectedColour = $(this).attr('id').match(/[0-9]{2}-[0-9]{3}-[0-9A-Z]{2}$/)[0];
			var loadCount = 0;
			var cacheTimeout;
				
			if (selectedColour == currentColour) {
				clearZoom(); //just reset
				return;	
			}
			
			var imageRegisterLoad = function() {
				loadCount++;
				if (loadCount==imageFilenames.length) {
					imageLoad();	
				}
			}
			
			var imageLoad = function(e) {

				if ($.browser.msie) {
					clearTimeout(cacheTimeout);
				}
				
				$(self).find('.image-load').hide();
				$("#preview-thumbs .preview-thumb:eq(0) img, #preview-thumbs .preview-thumb:eq(1) img").fadeOut(500);
				$("#preview-image div:eq("+(index?0:1)+")").hide();
				$("#preview-image div:eq("+index+")").fadeOut(500,function() {
					
					//reset selected image & drag and zoom
					index = 0;
					clearZoom();
					
					//replace images
					$("#preview-image div:eq(0) img:eq(0)").attr('src',imagePath + selectedColour + imageFilenames[0]);
					$("#preview-image div:eq(0) img:eq(1)").attr('src',imagePath + selectedColour + imageFilenames[1]);
					$("#preview-image div:eq(1) img:eq(0)").attr('src',imagePath + selectedColour + imageFilenames[2]);
					$("#preview-image div:eq(1) img:eq(1)").attr('src',imagePath + selectedColour + imageFilenames[3]);
					$("#preview-thumbs .preview-thumb:eq(0) img").attr('src',imagePath + selectedColour + imageFilenames[4]);
					$("#preview-thumbs .preview-thumb:eq(1) img").attr('src',imagePath + selectedColour + imageFilenames[5]);
				
					//show
					$("#preview-image div:eq(0)").fadeIn(500,function() {
						$(self).find('.image-zoom').show();
						$("#preview-image div:eq(1)").show();
					});
					$("#preview-thumbs .preview-thumb:eq(0) img, #preview-thumbs .preview-thumb:eq(1) img").fadeIn(500);
					
					loadedColours.push(selectedColour); //register loaded colour
					currentColour = selectedColour;
				});
				
				

			};
					
			$(self).find('.image-zoom').hide();
			$(self).find('.image-load').show();
			
			if (selectedColour != defaultColour && !inArray(selectedColour, loadedColours)) { 
				
				//preload images
				$.each(imageFilenames,function(k,v) {
					$('<img>').attr('src', imagePath + selectedColour + v).load(imageRegisterLoad);
				});
				
				if ($.browser.msie) {
					//IE doesn't fire all load events for cached images...
					cacheTimeout = setTimeout(imageLoad,1000);
				}
				
				
			} else {
				imageLoad(); 
			}
			
		});
	}
	
	var openWin = function(loc,name,width,height,scrollbars) {
		var sY = (screen.height - height) / 2 ; var sX = (screen.width - width) / 2;
		var popupWin = window.open(loc,name,'scrollbars='+scrollbars+',top='+sY+',left='+sX+',height='+height+',width='+width+''); //not global
		popupWin.focus();
	}
	
	var inArray = function (needle, haystack) {
		var key = '';
		for (key in haystack) {
			if (haystack[key] == needle) {
				return true;
			}
		}
		return false;
	}
	
	var ie_lt_7 = $.browser.msie && parseInt($.browser.version, 10) < 7 && parseInt($.browser.version, 10) > 4;
	var ie_lt_8 = $.browser.msie && parseInt($.browser.version, 10) < 8 && parseInt($.browser.version, 10) > 4;
	
	$(function() { //DOM load
	
		//common
		/*if(typeof sIFR == "function" && !$.browser.msie){
			sIFR.replaceElement("#nav a span",
				named({sFlashSrc:'/avantgarde_medium.swf', sColor:'#333333', sWmode: "transparent", sFlashVars: "textalign=center" })
			);
		}*/
		
		//Notification
		if ($("p.notification").length) {
			var notify = new logicbox.Dialog({fadeIn:false});
			notify.show($("p.notification").text());
			$("p.notification").remove();
		}

		$("ul#nav li").simplyDropdown();
		$(".subnav ul").simplyShadow();
		regionSelector();
		
		$("a[rel=popup]").click(function() {
			openWin($(this).attr('href'),'popup',1000,700,'yes');	
			return false;
		});
		
		 $('#content img,#header img').bind('contextmenu',function() {return false;}); 
		
		//product
		if ($("#preview").length) {
			$("#preview").preview();
			
			$(".related-item").click(function() {
				document.location = $(this).find('a').attr('href');							  
			});
			$(".related-item a").click(function(e) {
				e.stopPropagation();	
				return true;
			});
		}
		
		//category
		if ($(".subcat-container").length) {
			$(".subcat").products();	
		}
		
		//sub-cat
		if ($("#subcat-listing").length && !ie_lt_7) {
			
			$("#subcat-listing li").wrapInner('<div/>').hoverIntent(function(){
				$(this).stop(true).animate({top:"-20px"},500);
			},function() {
				$(this).animate({top:0},500);
			});
		}
		
		//home	
		if ($("body.p_home").length) {
			$(window).load(function() { //onload
				$('.cycle').cycle({
					fx: 'fade',
					timeout: 5000,
					speed: 1000
				});
			});
		}
		
		//contacts
		if ($(".p_contacts .country-container").length) {
			$(".p_contacts .country-outer").addClass('dropshadow-vert-right').wrap('<div class="dropshadow"></div>').before('<div class="dropshadow-corner-rb"></div><div class="dropshadow-end-bl"></div><div class="dropshadow-horz-bottom"></div>');
			$(".p_contacts .country-outer").parent().find('.dropshadow-horz-bottom').css('width',$('.country-inner').outerWidth()-6 + 'px');
		}
		
		if ($("ul#contacts").length) {
			$("ul#contacts li:last").addClass('last');
		}
		
		//Fix z-index ordering in IE 7 and below
		if (ie_lt_8) {
			var zIndexNumber = 1000;
			if ( $('div#signup-dialog').length ) {
				var dialog = $('div#signup-dialog').clone(true);
				$('div#signup-dialog').remove();
				$("body").prepend(dialog);
			}
			$('div.subnav,ul#nav,div#header,div#lang-selector,div#system-bar,div.cycle img,div.subcat-overlay,div.subcat,div#main').each(function() {
				$(this).css('z-index',zIndexNumber);
				zIndexNumber -= 10;
			});	
		}
		
		//Transparent PNGs (< IE 6)
		if (ie_lt_7) {
			var alphaEls = ['#lang img','#lang-selector img','.item-2 img','.item-3 img','.subcat p.title','.subcat img','.subcat-new img','#subcat-listing img','#preview .image-zoom','ul#contacts li','.view-usa','#landing-container ul img'];
			$(alphaEls.join(",")).supersleight();	
		}
		
	});	
	
})(jQuery);
(function($){
	logicbox.prototype = $.extend(logicbox, {
		Dialog: function(options) {
			
			this.options = {
				fadeIn: true,
				fadeOut: true,
				dialogClass: ".dialog",
				dialogTimeout: 5000
			};
			
			//override defaults with options
			this.options = $.extend(this.options,options);
		}
	});
	
	logicbox.Dialog.prototype = $.extend(logicbox.Dialog, {
		show: function(dialogText) {
			this.$dialog = $(this.options.dialogClass).clone();
			this.$dialog.find('p').text(dialogText).end().appendTo('body');
			//setup event
			var self = this,
				funcClose = function() { self.close(); return false; };
			
			$("a",this.$dialog).click(funcClose);
			this.timeout = setTimeout(funcClose,this.options.dialogTimeout);
			this.options.fadeIn ? this.$dialog.fadeIn(500) : this.$dialog.show();
		},
		close: function() {
			var self=this,funcDestroy = function() { self.destroy() };
			clearTimeout(this.timeout);
			this.options.fadeOut ? this.$dialog.fadeOut(500,funcDestroy) : this.$dialog.hide(this.funcDestroy);
			
		},
		destroy: function() {
			this.$dialog.remove();
			this.$dialog=null;
		}
	});
	
	logicbox.prototype = $.extend(logicbox, {
		newWin: function(el) {
			if (el===undefined) {
				el = this;
			}
			var w = window.open($(el).attr('href'),'_blank');
			w.focus();
			return false;
		},
		pageTrack: function(el,url) {
			//for dynamic/inline pageview only allow once per element
       		if (typeof pageTracker !== 'undefined' && typeof el.tracked === 'undefined') {
				if (typeof url === 'undefined') {
					url = $(el).attr('href');
				}
           		pageTracker._trackPageview(url);
				el.tracked=true;
        	}	
		},
		eventTrack: function(e,cat,str) {
			//get event type
			var type = typeof e !== 'string' ? e.type : e;			
			
			//if google analytics loaded
       	  	if (typeof pageTracker !== 'undefined') {
				pageTracker._trackEvent(cat,type,str);
          	}
		},
		validEvent: function(e) {
			key = this.keyCode(e);
			return ((typeof key === 'undefined' || key==0) || (key && key == 13)) ? true : false;
		},
		keyCode: function(e) {
			return e.charCode || e.keyCode;
		},
		arraySearch: function(needle, haystack) { //non-strict as opposed to $.inArray or .indexOf()
			var k;
			for (k in haystack) {
				if (haystack[k] == needle) {
					return k;
					break;
				}
			}	
		},
		urlPart: document.location.pathname.replace(/^\//,'').split('/'),
		validate: function(el,rules) {
			var error={};
			$(":input",el).each(
				function() {
					var attr = $(this).attr('name');
					var resp = validateField(this,rules[attr]);
					if (resp) {
						error[attr]=resp;
					}
				}
			);
			return error;
		},
		validateField: function (el,rule) {
			var error = false;
			var val  = $.trim($(el).val());
			if (typeof rule !== "undefined") {
				if (rule[0]===true && val=="") {
					error='required';
				}
				else if (typeof rule[1] !== "undefined" && rule[1] != "" && val!="") {					//do validation on field
					var regex = new RegExp("^" + rule[1] + "$","i"); 
					if (!regex.test(val)) {
						//failed
						error='invalid';
					}
				}
			}
			return error;
		},
		validateEmail: function(str) {
			return str.match(/[a-z0-9'\.\-_\+]+@[a-z0-9\-_]+\.([a-z0-9\-_]+\.)*?[a-z]+/i);
		},
		getCookie: function( name ) {
			var start = document.cookie.indexOf( name + "=" );
			var len = start + name.length + 1;
			if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
				return null;
			}
			if ( start == -1 ) return null;
			var end = document.cookie.indexOf( ';', len );
			if ( end == -1 ) end = document.cookie.length;
			return unescape( document.cookie.substring( len, end ) );
		},
		setCookie: function( name, value, expires, path, domain, secure ) {
			var today = new Date();
			today.setTime( today.getTime() );
			if ( expires ) {
				expires = expires * 1000 * 60 * 60 * 24;
			}
			var expires_date = new Date( today.getTime() + (expires) );
			document.cookie = name+'='+escape( value ) +
				( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
				( ( path ) ? ';path=' + path : '' ) +
				( ( domain ) ? ';domain=' + domain : '' ) +
				( ( secure ) ? ';secure' : '' );
		},
		deleteCookie: function ( name, path, domain ) {
			if ( getCookie( name ) ) document.cookie = name + '=' +
					( ( path ) ? ';path=' + path : '') +
					( ( domain ) ? ';domain=' + domain : '' ) +
					';expires=Thu, 01-Jan-1970 00:00:01 GMT';
		}
	});
	
	$(function() { //DOM load
			   
		$("a[rel=external]").bind('click keypress',
			function(e) {
				if (logicbox.validEvent(e)) {
					//only event track outgoing links
					if ($(this).attr('href').match(/^https?:\/\//)) {
						logicbox.eventTrack(e,'outgoing',$(this).attr('href'));
					}
					return logicbox.newWin(this);
				}
				return false;
			}
		);
		$("a[href^=mailto]").bind('click keypress',
			function(e) {
				if (logicbox.validEvent(e)) {
					logicbox.eventTrack(e,'email',$(this).attr('href'));
				}
				return true;
			}
		);
		$("a[href$=pdf],a[href$=zip]").bind('click keypress', 
			function(e){
				if (logicbox.validEvent(e)) {
					logicbox.pageTrack(this,e);
				}
			}
		);

	});
})(jQuery);
jQuery.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs: true,
		backgrounds: true,
		shim: '/images/x.gif',
		apply_positioning: true
	}, settings);
	
	return this.each(function(){
		//if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
			jQuery(this).find('*').andSelf().each(function(i,obj) {
				//console.log(this);
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.width() + 'px',
						'height': self.height() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
					self.css('position', 'relative');
				};
			});
		//};
	});
};

/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);