﻿
/* Copyright (c) 2007 Paul Bakaus (paul.bakaus@googlemail.com) and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-10-06 20:11:15 +0200 (Sa, 06 Okt 2007) $
 * $Rev: 3581 $
 *
 * Version: @VERSION
 *
 * Requires: jQuery 1.2+
 
(function($){	
$.dimensions = {
	version: '@VERSION'
};
$.each( [ 'Height', 'Width' ], function(i, name){
	$.fn[ 'inner' + name ] = function() {
		if (!this[0]) return;		
		var torl = name == 'Height' ? 'Top'    : 'Left',  
		    borr = name == 'Height' ? 'Bottom' : 'Right'; 
		return num( this, name.toLowerCase() ) + num(this, 'padding' + torl) + num(this, 'padding' + borr);
	};
	$.fn[ 'outer' + name ] = function(options) {
		if (!this[0]) return;
		
		var torl = name == 'Height' ? 'Top'    : 'Left', 
		    borr = name == 'Height' ? 'Bottom' : 'Right'; 
		options = $.extend({ margin: false }, options || {});		
		return num( this, name.toLowerCase() )
				+ num(this, 'border' + torl + 'Width') + num(this, 'border' + borr + 'Width')
				+ num(this, 'padding' + torl) + num(this, 'padding' + borr)
				+ (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0);
	};
});
$.each( ['Left', 'Top'], function(i, name) {
	$.fn[ 'scroll' + name ] = function(val) {
		if (!this[0]) return;
		return val != undefined ?
			this.each(function() {
				this == window || this == document ?
					window.scrollTo( 
						name == 'Left' ? val : $(window)[ 'scrollLeft' ](),
						name == 'Top'  ? val : $(window)[ 'scrollTop'  ]()
					) :
					this[ 'scroll' + name ] = val;
			}) :
			this[0] == window || this[0] == document ?
				self[ (name == 'Left' ? 'pageXOffset' : 'pageYOffset') ] ||
					$.boxModel && document.documentElement[ 'scroll' + name ] ||
					document.body[ 'scroll' + name ] :
				this[0][ 'scroll' + name ];
	};
});

$.fn.extend({
	position: function() {
		var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
		if (elem) {
			offsetParent = this.offsetParent();
			offset       = this.offset();
			parentOffset = offsetParent.offset();
			offset.top  -= num(elem, 'marginTop');
			offset.left -= num(elem, 'marginLeft');
			parentOffset.top  += num(offsetParent, 'borderTopWidth');
			parentOffset.left += num(offsetParent, 'borderLeftWidth');
			var results={
				top:  offset.top  - parentOffset.top,
				left: offset.left - parentOffset.left
		    };
		}		
		return results;
	},	
	offsetParent: function() {
		var offsetParent = this[0].offsetParent;
		while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && $.css(offsetParent, 'position') == 'static') )
			offsetParent = offsetParent.offsetParent;
		return $(offsetParent);
	}
});
function num(el, prop) {
	return parseInt($.css(el.jquery?el[0]:el,prop))||0;
};
})(jQuery);
*/
/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-06-20 16:25:35 -0500 (Wed, 20 Jun 2007) $
 * $Rev: 2125 $
 *
 * Version: 2.2
 
(function($){$.fn.extend({mousewheel:function(f){if(!f.guid)f.guid=$.event.guid++;if(!$.event._mwCache)$.event._mwCache=[];return this.each(function(){if(this._mwHandlers)return this._mwHandlers.push(f);else this._mwHandlers=[];this._mwHandlers.push(f);var s=this;this._mwHandler=function(e){e=$.event.fix(e||window.event);$.extend(e,this._mwCursorPos||{});var delta=0,returnValue=true;if(e.wheelDelta)delta=e.wheelDelta/120;if(e.detail)delta=-e.detail/3;if(window.opera)delta=-e.wheelDelta;for(var i=0;i<s._mwHandlers.length;i++)if(s._mwHandlers[i])if(s._mwHandlers[i].call(s,e,delta)===false){returnValue=false;e.preventDefault();e.stopPropagation();}return returnValue;};if($.browser.mozilla&&!this._mwFixCursorPos){this._mwFixCursorPos=function(e){this._mwCursorPos={pageX:e.pageX,pageY:e.pageY,clientX:e.clientX,clientY:e.clientY};};$(this).bind('mousemove',this._mwFixCursorPos);}if(this.addEventListener)if($.browser.mozilla)this.addEventListener('DOMMouseScroll',this._mwHandler,false);else this.addEventListener('mousewheel',this._mwHandler,false);else
this.onmousewheel=this._mwHandler;$.event._mwCache.push($(this));});},unmousewheel:function(f){return this.each(function(){if(f&&this._mwHandlers){for(var i=0;i<this._mwHandlers.length;i++)if(this._mwHandlers[i]&&this._mwHandlers[i].guid==f.guid)delete this._mwHandlers[i];}else{if($.browser.mozilla&&!this._mwFixCursorPos)$(this).unbind('mousemove',this._mwFixCursorPos);if(this.addEventListener)if($.browser.mozilla)this.removeEventListener('DOMMouseScroll',this._mwHandler,false);else this.removeEventListener('mousewheel',this._mwHandler,false);else
this.onmousewheel=null;this._mwHandlers=this._mwHandler=this._mwFixCursorPos=this._mwCursorPos=null;}});}});$(window).one('unload',function(){var els=$.event._mwCache||[];for(var i=0;i<els.length;i++)els[i].unmousewheel();});})(jQuery);


(function($){   
 $.fn.centreV = function(opts) {  
    var defaults = { 
        containerHeight:null
    };   
    var options = $.extend(defaults, opts);
    return this.each(function() { 
        var selfref = $(this);
        if(options.containerHeight == null){
            options.containerHeight = selfref.parent().height();
        }
        function centreMe(){
            var newTop= Math.floor((options.containerHeight/2) -(selfref.outerHeight()/2));
            if(newTop<0){newTop=0;}
            selfref.css("position","relative").css("top",newTop+"px");
        }           
        centreMe();         
        selfref.bind("load",function(){centreMe();});
        $("img",selfref).bind("load",function(){centreMe();});        
    });   
 };   
})(jQuery);

/* crosssellmouseovers() controls the mouseovers in the cross sell section of the product page */
(function($){   
 $.fn.crosssellmouseovers = function() {  
    var defaults = {                
    };   
    var options = $.extend(defaults, options);  
    return this.each(function() {
        var selfref = $(this); 
        var cells=$('td',selfref);
        var items_count=cells.length;
        var items_per_row = $('td',$($('tr',selfref)[0])).length;
        var last_row_starts=(Math.floor((items_count-1)/items_per_row) * items_per_row);
        for(i=0;i<items_count;i++){
            var this_cell=$(cells[i]);
            var my_img = $('.cross_sell_image',this_cell);
            var cls="col_";
            var pointer_src="/images/icon_prod_arrowup.gif";
            if(i >= last_row_starts){
                cls="col_last_"
                pointer_src="/images/icon_prod_arrowdown.gif";
            }
            var mod = i%items_per_row;
            if(mod==0){
                cls+="left";
            }else if (mod==items_per_row-1){
                cls+="right";
            }else{
                cls+="center";
            }
           this_cell.addClass(cls);           
           this_cell.append('<div class="cross_sell_pointer" style="position:absolute;display:none;width:11px;height:11px;"><img src="'+pointer_src+'"  alt=""/></div>');
                       
        }        
        $('.cross_sell_item',selfref).each(function(){
            var item = $(this);
            var myLnk= $('.cross_sell_image a',item);
            var myImg = $('.cross_sell_image img',item);
            var myTeaser = $('.cross_sell_teaser',item);
            var myPointer = $('.cross_sell_pointer',item);
            myLnk.attr('alt','').attr('title','');
			myImg.attr('alt','').attr('title','');
            function ov(){              
                var baseL =  myLnk.offset().left;
                var baseT =  myLnk.offset().top;
                if($.browser.msie && $.browser.version <7 && $('body').outerWidth() > 984){
                    baseL -= ($('body').outerWidth() - 984)/2;
                }
                var teaser_l = baseL; 
                var teaser_t = baseT + myLnk.outerHeight()+ myPointer.outerHeight();
                
                var pointer_l = baseL + Math.floor(myPointer.outerWidth()/2);
                var pointer_t = baseT + myLnk.outerHeight()+1;
                
                if(item.hasClass('col_last_center') || item.hasClass('col_center')){
                    teaser_l -= Math.floor((myTeaser.outerWidth()-myLnk.outerWidth())/2);
                    pointer_l = baseL + Math.floor((myLnk.outerWidth() - myPointer.outerWidth())/2);
                    
                }else if(item.hasClass('col_last_right') || item.hasClass('col_right')){
                    teaser_l -= Math.floor((myTeaser.outerWidth()-myLnk.outerWidth()));
                    pointer_l = baseL + myLnk.outerWidth() - (Math.floor(myPointer.outerWidth()*1.5));
                }
                if(item.hasClass('col_last_center') || item.hasClass('col_last_right') || item.hasClass('col_last_left')){
                    teaser_t = baseT - myPointer.outerHeight() - myTeaser.outerHeight() + 1;
                    pointer_t = baseT - myPointer.outerHeight();
                }
                myTeaser.css({
                    'position':'absolute',
                    'top':teaser_t,
                    'left':teaser_l,
                    'display':'block',
                    'z-index':'99'                    
                });
                myPointer.css({
                    'position':'absolute',
                    'top':pointer_t,
                    'left':pointer_l,
                    'display':'block',
                    'z-index':'100'                     
                });
				return false;
            }
             function ou(){
                myTeaser.css('display','none');
                myPointer.css('display','none');
				return false;
            }            
            myLnk.hover(ov,ou);
        });    
    });   
 };   
})(jQuery);

var sendtobottomfunction;
/* sendtobottom() ensures that the next/previous controls are at the bottom of their container */
(function($){   
 $.fn.sendtobottom = function(opts) {  
    var defaults = {  
    };   
    var options = $.extend(defaults, opts);  
    return this.each(function() { 
        var selfref=$(this);
        var pusher=$('.next_prev_spacer img',selfref);        
        function reposition_me(v){
            pusher.css('height','1px');           
           var cols_to_match=$('.column1, .column3');
           var myCol = selfref.parent();           
            myCol.css('height','auto');
             var maxH = $('.maincontainer').innerHeight() - $('.maincontainer').offset().top - myCol.offset().top;			 
             if(myCol.outerHeight() > maxH){
                maxH = myCol.outerHeight();
             }
            var myColH = myCol.outerHeight();
            cols_to_match.each(function(){
                var colH=$(this).outerHeight();
                if(colH > maxH){
                   maxH = colH; 
                }
            });
            if(myColH<maxH){                
                 pusher.css('width','1px');
            	pusher.css('height',(maxH-myColH+1)+'px');
            }
        }
        reposition_me();
 	    if($.browser.msie){
        $('.column1,.column3').bind('resize',function(){
        reposition_me();          
       });
	   }else{
		  $('.column1 img,.column3 img').bind('load',function(){
            reposition_me();
          });
          $('.Colour a, a.more_link ').bind('click',function(){
            reposition_me();
          });  
	$('.accordion_content ').bind('change',function(){
				reposition_me();          
		    });
       }
		accordion_resized = function(v){reposition_me(v);}
    });   
 };   
})(jQuery);


var columnSizer;
runOnLoad = function (){  	
    $('.accordion').accordion({header:'.accordion_heading', selectedClass:'accordion_open',  alternatingHeading1:'accordion_heading_odd',  alternatingHeading2:'accordion_heading_even'});  
    $(".cross_sell").crosssellmouseovers();
    $('.next_prev').sendtobottom();
}

// Additional Scripts (S. Frater - 12/06/2009)

// Ajax call to add item to cart 
function AddToCart() {
    // Get vars from hidden fields
    var size = $("#AddToCartForm input[name = 'szID']").val();
    var colour = $("#AddToCartForm input[name = 'clID']").val();
    var prod = $("#AddToCartForm input[name = 'pdID']").val();
    var cat = $("#AddToCartForm input[name = 'catID']").val();
    if (isNaN(cat)) {cat = 0;}
    var quantity = $("#AddToCartForm input[name = 'qty']").val();

    if (quantity && size && colour && quantity > 0 && size >= 0 && colour >= 0) {
        $.ajax({
            type: "GET",
            url: "/default.aspx",
            cache: false,
            data: { z: "c", action: "addspecify", qs: "8", pdID: prod, catID: cat, szID: size, clID: colour, qty: quantity, addpopup: "1" },
           success: ShowAddToCartPopup
        });
    } else {
        alert("Please select the colour and size that you require before adding this item to your cart");
    }
    return false; // Prevent form submit
}


/*

function ShowEmailAFriendForm() {
    var eventObj = this;
    alert('in email a friend script');
    var prod = parseInt($("input[name = 'pdID']").val());
    if (prod > 0) {
        $.get(
            "/support.aspx",
            { iSAMS: "emailafriend", pdID: prod }, function(data) {
                $("#email-a-friend").html(data);
                popup(2, 'email-a-friend', eventObj);
                InitEmailAFriendForm();
            }
        );
    }
    return false;
}

function InitEmailAFriendForm() {
    $("div.email_a_friend form").submit(function() {
        $("#email-a-friend-progress").css("visibility", "visible");
        $("#email-a-friend-messages").hide();
        $.post(
        "/", $("div.email_a_friend form").serializeArray(), function(data) {
            $("#email-a-friend-progress").css("visibility", "hidden");
            $("#email-a-friend-messages").html(data);
            $("#email-a-friend-messages").slideDown();
        }
        );
        return false;
    });
}
*/

function popup(popuptype, identifier, clicked) {
    clicked.href = 'javascript:void(0)';
    if (popuptype == 1) {
        // type 1 = zoom image
        var w = dhtmlwindow.open('popupbox_zoom', 'ajax', identifier, undefined, 'width=628px,height=660px,center=1,resize=0,scrolling=0');
        $('.drag-contentarea', w).css({ 'height': 'auto', 'overflow': 'auto' });
    } else if (popuptype == 2) {
        //type 2 = special offer, write/read review
        var w = dhtmlwindow.open('popupbox_' + identifier, 'div', identifier, undefined, 'width=628px,height=600px,center=1,resize=0,scrolling=0');
        $('.popup_heading h1, .product_preview .ItemName', w).sifr({ path: '/images/', font: 'Gill_Sans_MT_Light', textAlign: 'left' });
        $('h1.products, .email_a_friend .ItemName', w).sifr({ path: '/images/', font: 'Gill_Sans_MT_Light_nospace', textAlign: 'left' });
        $(' .product_preview .ItemBrand, .email_a_friend .ItemBrand', w).sifr({ path: '/images/', font: 'Gill_Sans_MT', textAlign: 'left' });
        $('.drag-contentarea', w).css({ 'height': 'auto', 'overflow': 'auto' });
    } else if (popuptype == 3) {
        //type 3 = product preview
        var w = dhtmlwindow.open('popupbox_product', 'ajax', identifier, undefined, 'width=628px,height=660px,center=1,resize=0,scrolling=0');
        //dhtmlwindow code has been modified to add the sifr functions when the ajax has loaded
        $('.drag-contentarea', w).css({ 'height': 'auto', 'overflow': 'auto' });
    }
    return false;
}
