/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.1, 11.09.2007
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Changelog:
 *    11.09.2007 Version 1.1
 *    - removed noConflict
 *    - added png-support for input type=image
 *    - 01.08.2007 CSS background-image support extension added by Scott Jehl, scott@filamentgroup.com, http://www.filamentgroup.com
 *    31.05.2007 initial Version 1.0
 * --------------------------------------------------------------------
 * @example $(function(){$(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready
 *
 * jQuery(function(){jQuery(document).pngFix();});
 * @desc Fixes all PNG's in the document on document.ready when using noConflict
 *
 * @example $(function(){$('div.examples').pngFix();});
 * @desc Fixes all PNG's within div with class examples
 *
 * @example $(function(){$('div.examples').pngFix( { blankgif:'ext.gif' } );});
 * @desc Fixes all PNG's within div with class examples, provides blank gif for input with png
 * --------------------------------------------------------------------
 */

(function($) {

jQuery.fn.pngFix = function(settings) {

	// Settings
	settings = jQuery.extend({
		blankgif: 'blank.gif'
	}, settings);

	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

	if (jQuery.browser.msie && (ie55 || ie6)) {

		//fix images with png-source
		jQuery(this).find("img[@src$=.png]").each(function() {

			jQuery(this).attr('width',jQuery(this).width());
			jQuery(this).attr('height',jQuery(this).height());

			var prevStyle = '';
			var strNewHTML = '';
			var imgId = (jQuery(this).attr('id')) ? 'id="' + jQuery(this).attr('id') + '" ' : '';
			var imgClass = (jQuery(this).attr('class')) ? 'class="' + jQuery(this).attr('class') + '" ' : '';
			var imgTitle = (jQuery(this).attr('title')) ? 'title="' + jQuery(this).attr('title') + '" ' : '';
			var imgAlt = (jQuery(this).attr('alt')) ? 'alt="' + jQuery(this).attr('alt') + '" ' : '';
			var imgAlign = (jQuery(this).attr('align')) ? 'float:' + jQuery(this).attr('align') + ';' : '';
			var imgHand = (jQuery(this).parent().attr('href')) ? 'cursor:hand;' : '';
			if (this.style.border) {
				prevStyle += 'border:'+this.style.border+';';
				this.style.border = '';
			}
			if (this.style.padding) {
				prevStyle += 'padding:'+this.style.padding+';';
				this.style.padding = '';
			}
			if (this.style.margin) {
				prevStyle += 'margin:'+this.style.margin+';';
				this.style.margin = '';
			}
			var imgStyle = (this.style.cssText);

			strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
			strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
			strNewHTML += 'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;';
			strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + jQuery(this).attr('src') + '\', sizingMethod=\'scale\');';
			strNewHTML += imgStyle+'"></span>';
			if (prevStyle != ''){
				strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + jQuery(this).width() + 'px;' + 'height:' + jQuery(this).height() + 'px;'+'">' + strNewHTML + '</span>';
			}

			jQuery(this).hide();
			jQuery(this).after(strNewHTML);

		});

		// fix css background pngs
		jQuery(this).find("*").each(function(){
			var bgIMG = jQuery(this).css('background-image');
			if(bgIMG.indexOf(".png")!=-1){
				var iebg = bgIMG.split('url("')[1].split('")')[0];
				jQuery(this).css('background-image', 'none');
				jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
			}
		});
		
		//fix input with png-source
		jQuery(this).find("input[@src$=.png]").each(function() {
			var bgIMG = jQuery(this).attr('src');
			jQuery(this).get(0).runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + bgIMG + '\', sizingMethod=\'scale\');';
   		jQuery(this).attr('src', settings.blankgif)
		});	
	}	
	return jQuery;

};

})(jQuery);

/* tabulate */
(function($){   
 $.fn.tabulate = function(opts) {  
    var defaults = {  
		cell_selector:'.Item'
    };   
    var o = $.extend(defaults, opts);  
    return this.each(function() { 
		var selfref=$(this);
        var cells = $(o.cell_selector,selfref).css({'float':'left','display':'block'});
		var cols = Math.floor(selfref.innerWidth()/cells.outerWidth());
		if(cells.length > 0){
			cells.each(function(i){
				if(i%cols == cols-1 || i == cells.length-1){
					$(this).after($('<div class="divider" style="clear:left"></div>'));
				}
			});				
			var heights=[];
			function setHeights(e){
				cells.each(function(i){
					var myRow=Math.floor(i/cols);
					$(this).css("height","auto");
					var myH = $(this).height();
					if(heights[myRow]==undefined || heights[myRow]==null || heights[myRow] < myH){
						heights[myRow]=myH;
					}
				});	
				cells.each(function(i){
					var myRow=Math.floor(i/cols);
					 $(this).css("height",heights[myRow]+"px");				
				});				
			}
			$('img',cells).bind('load',function(e){setHeights(e);});
			setHeights();			
		}
    });   
 };   
})(jQuery);


// popup function appears on the product page and can be used to display different types of page.
// the dimensions etc of the pop-ups can be modified here to suit the site and page type
// Current page types:
//	1 = info page (size chart, delivery details etc)
//  2 = image zoom either a large image, or the zoomify component
function popup(popupType, popUpURL){
	if(popupType == 1){
		window.open(popUpURL, "info_window", "width=550,height=580,toolbar=no,header=no,location=no,resizable=1,scrollbars=0");	
	}else if(popupType == 2){
		window.open(popUpURL, "zoom_window", "width=550,height=580,toolbar=no,header=no,location=no,resizable=1,scrollbars=0");	
	}else{
		window.open(popUpURL, "info_window", "width=400,height=420,toolbar=no,header=no,location=no,resizable=1,scrollbars=0");
	}
}


;(function(){var $$;$$=jQuery.fn.flash=function(htmlOptions,pluginOptions,replace,update){var block=replace||$$.replace;pluginOptions=$$.copy($$.pluginOptions,pluginOptions);if(!$$.hasFlash(pluginOptions.version)){if(pluginOptions.expressInstall&&$$.hasFlash(6,0,65)){var expressInstallOptions={flashvars:{MMredirectURL:location,MMplayerType:'PlugIn',MMdoctitle:jQuery('title').text()}};}else if(pluginOptions.update){block=update||$$.update;}else{return this;}}htmlOptions=$$.copy($$.htmlOptions,expressInstallOptions,htmlOptions);return this.each(function(){block.call(this,$$.copy(htmlOptions));});};$$.copy=function(){var options={},flashvars={};for(var i=0;i<arguments.length;i++){var arg=arguments[i];if(arg==undefined)continue;jQuery.extend(options,arg);if(arg.flashvars==undefined)continue;jQuery.extend(flashvars,arg.flashvars);}options.flashvars=flashvars;return options;};$$.hasFlash=function(){if(/hasFlash\=true/.test(location))return true;if(/hasFlash\=false/.test(location))return false;var pv=$$.hasFlash.playerVersion().match(/\d+/g);var rv=String([arguments[0],arguments[1],arguments[2]]).match(/\d+/g)||String($$.pluginOptions.version).match(/\d+/g);for(var i=0;i<3;i++){pv[i]=parseInt(pv[i]||0);rv[i]=parseInt(rv[i]||0);if(pv[i]<rv[i])return false;if(pv[i]>rv[i])return true;}return true;};$$.hasFlash.playerVersion=function(){try{try{var axo=new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');try{axo.AllowScriptAccess='always';}catch(e){return'6,0,0';}}catch(e){}return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g,',').match(/^,?(.+),?$/)[1];}catch(e){try{if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){return(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g,",").match(/^,?(.+),?$/)[1];}}catch(e){}}return'0,0,0';};$$.htmlOptions={flashvars:{},pluginspage:'http://www.adobe.com/go/getflashplayer',src:'#',type:'application/x-shockwave-flash'};$$.pluginOptions={expressInstall:false,update:true,version:'6.0.65'};$$.replace=function(htmlOptions){this.innerHTML='<div class="alt">'+this.innerHTML+'</div>';jQuery(this).addClass('flash-replaced').prepend($$.transform(htmlOptions));};$$.update=function(htmlOptions){var url=String(location).split('?');url.splice(1,0,'?hasFlash=true&');url=url.join('');var msg='<p>This content requires the Flash Player. <a href="http://www.adobe.com/go/getflashplayer">Download Flash Player</a>. Already have Flash Player? <a href="'+url+'">Click here.</a></p>';this.innerHTML='<span class="alt">'+this.innerHTML+'</span>';jQuery(this).addClass('flash-update').prepend(msg);};function toAttributeString(){var s='';for(var key in this)if(typeof this[key]!='function')s+=key+'="'+this[key]+'" ';return s;};function toFlashvarsString(){var s='';for(var key in this)if(typeof this[key]!='function')s+=key+'='+encodeURIComponent(this[key])+'&';return s.replace(/&$/,'');};$$.transform=function(htmlOptions){htmlOptions.toString=toAttributeString;if(htmlOptions.flashvars)htmlOptions.flashvars.toString=toFlashvarsString;return'<embed '+String(htmlOptions)+'/>';};if(window.attachEvent){window.attachEvent("onbeforeunload",function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};});}})();

jQuery.fn.sifr=function(prefs){var p=jQuery.extend((prefs===false)?{unsifr:true}:{},arguments.callee.prefs,prefs);if(p.save){arguments.callee.prefs=jQuery.extend(p,{save:false});}if(this[0]===document){return;}if(!p.unsifr&&typeof p.before==='function'){p.before.apply(this,[p]);}this.each(function(){var t=jQuery(this);var a=t.children('.sIFR-alternate');if(a){t.html(a.html());if(p.unsifr){return;}}if(typeof p.beforeEach==='function'){p.beforeEach.apply(this,[t,p]);}var s=t.html('<span class="flash-replaced sIFR-replaced">'+(p.content||t.html()).replace(/^\s+|\s+$/g,'')+'</span>').children();a=t.append('<span class="alt sIFR-alternate">'+s.html()+'</span>').children('.sIFR-alternate');if(a.css('display')!=='none'){a.css('display','none');}var toHex=function(c){var h=function(n){if(n===0||isNaN(n)){return'00';}n=Math.round(Math.min(Math.max(0,n),255));return'0123456789ABCDEF'.charAt((n-n%16)/16)+'0123456789ABCDEF'.charAt(n%16);};c=(c)?c.replace(/rgb|\(|\)|#$/g,''):false;if(!c){return false;}if(c.indexOf(',')>-1){c=c.split(', ');return'#'+h(c[0])+h(c[1])+h(c[2]);}if(c.search('#')>-1&&c.length<=4){c=c.split('');return'#'+c[1]+c[1]+c[2]+c[2]+c[3]+c[3];}return c;};if(p.textTransform){if(p.textTransform.toLowerCase()==='uppercase'){s.html(s.html().toUpperCase());}if(p.textTransform.toLowerCase()==='lowercase'){s.html(s.html().toLowerCase());}if(p.textTransform.toLowerCase()==='capitalize'){var c=s.html().replace(/\>/g,'> ').split(' ');for(var i=0;i<c.length;i=i+1){c[i]=c[i].charAt(0).toUpperCase()+c[i].substring(1);}s.html(c.join(' ').replace(/\> /g,'>'));}}var f={flashvars:jQuery.extend({h:s.height()*(p.zoom||1),offsetLeft:p.offsetLeft||undefined,offsetTop:p.offsetTop||undefined,textAlign:p.textAlign||(/(left|center|right)/.exec(t.css('textAlign'))||['center'])[0],textColor:toHex(p.color||t.css('color'))||undefined,txt:p.content||s.html(),underline:(p.underline||(p.underline!==false&&t.css('textDecoration')==='underline'))?true:undefined,w:(p.width||s.width())*(p.zoom||1)},p.flashvars),height:p.height||s.height(),src:(p.path||'')+((p.path&&p.path.substr(p.path.length-1)!=='/')?'/':'')+(p.font||'')+((p.font&&p.font.indexOf('.swf')===-1)?'.swf':''),width:p.width||s.width(),wmode:'transparent'};f.flashvars.linkColor=toHex(p.link||t.find('a').css('color'))||f.flashvars.textColor;f.flashvars.hoverColor=toHex(p.hover)||f.flashvars.linkColor;if(p.zoom){f.flashvars.offsetTop=((p.offsetTop||0)+((s.height()-(s.height()*p.zoom))/2))*(p.zoomTop||1);f.flashvars.offsetLeft=((p.offsetLeft||0)+((s.width()-(s.width()*p.zoom))/2))*(p.zoomLeft||1);}t.flash(jQuery.extend(f,p.embedOptions),jQuery.extend({expressInstall:p.expressInstall||false,version:p.version||7,update:p.update||false},p.pluginOptions),function(f){var preHeight=t.height();var preWidth=t.width();s.html(jQuery.fn.flash.transform(f));var e=s.find(':first');e.css({verticalAlign:'text-bottom',display:'inline',width:p.width,height:p.height});var marginBottom=preHeight-t.height();var width=parseInt(e.css('width'),10)+parseInt(preWidth-t.width(),10);if(!p.height){e.css({marginBottom:marginBottom});}if(!p.width){e.css({width:width});}if(p.height&&p.verticalAlign==='middle'){e.css({marginTop:Math.floor((p.height-s.height())/2),marginBottom:Math.round((p.height-s.height())/2),height:s.height()});e.attr('height',s.height());}if(p.height&&p.verticalAlign==='bottom'){var a=t.find('.sIFR-alternate');e.css({marginTop:(p.height-s.height()),height:s.height()});e.attr('height',s.height());}if(p.css){e.css(p.css);}});if(typeof p.afterEach==='function'){p.afterEach.apply(this,[t,p]);}});if(!p.unsifr&&typeof p.after==='function'){p.after.apply(this,[p]);}};jQuery.sifr=function(prefs){jQuery().sifr(jQuery.extend({save:true},prefs));};jQuery.fn.unsifr=function(){return this.each(function(){jQuery(this).sifr(false);});};

$(document).ready(function(){
	// Make the catalogue and search listings behave like a table by
	// matching the heights of the cells in each row and adding a clear:left
	// div at the end of each row
	$('.Listing').tabulate();
	$('.CrossSell, .Related_Products').tabulate();

	// Do the same for the catalogues in the sitemap	
	$('.SiteMap').tabulate({cell_selector:'.sitemap_catalogue'});

	// Add some padding to the heading on the Contact Us page	
	$('.content_column_2 h1:contains("How to contact us")').css('padding','18px');
	$('.content_column_2 table:contains("How to contact us")').css({'background-color':'#D4CBC2','width':'723px','margin-bottom':'20px'});	
	$('.content_column_2 label:contains("Security Code (case sensitive):")').css('display','block');
	
	
	// Replace the words 'Top Nav' in the dynamic section heading in the left hand column
	$('.nav_hierarchy h2:contains("Top Nav")').html('Information');
	
	//$('.nav_hierarchy h2, .InfoPage h1, .ProductDescription h2.ItemName, .CartHeading .mainheading, .content_column_2 h1:contains("How to contact us"), .ProductDetails .PriceNow, .CrossSell .CrossSell_heading' ).sifr({path:'/assets/',font:'VAGRounded',textAlign: 'left'});
;})
