function initPage()
{
	initAutoScalingNav({
		menuId: "main-menu",
		spacing: 2,
		tag: "a",
		constant: -2
	});
}
function initAutoScalingNav(o)
{
	if (!o.menuId) o.menuId = "main-menu";
	if (!o.tag) o.tag = "a";
	if (!o.spacing) o.spacing = 0;
	if (!o.constant) o.constant = 0;
	if (!o.minPaddings) o.minPaddings = 0;
	if (!o.liHovering) o.liHovering = false;
	if (!o.sideClasses) o.sideClasses = false;
	var nav = document.getElementById(o.menuId);
	if(nav)
	{
		var lis = nav.getElementsByTagName("li");
		var asFl = [];
		var lisFl = [];
		for (var i=0, j=0; i<lis.length; i++)
		{
			if(lis[i].parentNode == nav)
			{
				var t = lis[i].getElementsByTagName(o.tag).item(0);
				asFl.push(t);
				asFl[j++].width = t.offsetWidth;
				lisFl.push(lis[i]);
			}
			if(o.liHovering)
			{
				lis[i].onmouseover = function()
				{
					this.className += " hover";
				}
				lis[i].onmouseout = function()
				{
					this.className = this.className.replace("hover", "");
				}
			}
		}
		var menuWidth = nav.clientWidth - asFl.length*o.spacing - o.constant;
		if(getItemsWidth(asFl) < menuWidth)
		{
			for (var i=0; getItemsWidth(asFl) < menuWidth; i++)
			{
				asFl[i].width++;
				if(i >= asFl.length-1) i=-1;
			}
			for (var i=0; i<asFl.length; i++)
			{
				asFl[i].style.width = asFl[i].width + "px";
			}
		}
		else if(o.minPaddings > 0)
		{
			for (var i=0; i<asFl.length; i++)
			{
				asFl[i].style.width = asFl[i].width + o.minPaddings*2 + "px";
			}
		}
	}
	function getItemsWidth(a)
	{
		var w = 0;
		for(var q=0; q<a.length; q++)
		{
			w += a[q].width;
		}
		return w;
	}
	if(o.sideClasses)
	{
		lisFl[0].className += " first-child";
		lisFl[lisFl.length-1].className += " last-child";
	}
}
if (window.addEventListener)
	window.addEventListener("load", initPage, false);
else if (window.attachEvent)
	window.attachEvent("onload", initPage);;
function hideFormText() {
	var _inputs = document.getElementsByTagName('input');
	var _txt = document.getElementsByTagName('textarea');
	var _value = [];
	
	if (_inputs) {
		for(var i=0; i<_inputs.length; i++) {
			if (_inputs[i].type == 'text' || _inputs[i].type == 'password') {
				
				_inputs[i].index = i;
				_value[i] = _inputs[i].value;
				
				_inputs[i].onfocus = function(){
					if (this.value == _value[this.index])
						this.value = '';
				}
				_inputs[i].onblur = function(){
					if (this.value == '')
						this.value = _value[this.index];
				}
			}
		}
	}
	if (_txt) {
		for(var i=0; i<_txt.length; i++) {
			_txt[i].index = i;
			_value['txt'+i] = _txt[i].value;
			
			_txt[i].onfocus = function(){
				if (this.value == _value['txt'+this.index])
					this.value = '';
			}
			_txt[i].onblur = function(){
				if (this.value == '')
					this.value = _value['txt'+this.index];
			}
		}
	}
}
if (window.addEventListener)
	window.addEventListener("load", hideFormText, false);
else if (window.attachEvent)
	window.attachEvent("onload", hideFormText);;
/*
 *
 * Visage, Inc. javascript
 * 
 */

/*!
 * jQuery Cycle Lite Plugin
 * http://malsup.com/jquery/cycle/lite/
 * Copyright (c) 2008-2011 M. Alsup
 * Version: 1.3.1 (07-OCT-2011)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires: jQuery v1.3.2 or later
 */
;(function($) {

var ver = 'Lite-1.3';

$.fn.cycle = function(options) {
    return this.each(function() {
        options = options || {};
        
        if (this.cycleTimeout) clearTimeout(this.cycleTimeout);
        this.cycleTimeout = 0;
        this.cyclePause = 0;
        
        var $cont = $(this);
        var $slides = options.slideExpr ? $(options.slideExpr, this) : $cont.children();
        var els = $slides.get();
        if (els.length < 2) {
            window.console && console.log('terminating; too few slides: ' + els.length);
            return; // don't bother
        }

        // support metadata plugin (v1.0 and v2.0)
        var opts = $.extend({}, $.fn.cycle.defaults, options || {}, $.metadata ? $cont.metadata() : $.meta ? $cont.data() : {});
		var meta = $.isFunction($cont.data) ? $cont.data(opts.metaAttr) : null;
		if (meta)
			opts = $.extend(opts, meta);
            
        opts.before = opts.before ? [opts.before] : [];
        opts.after = opts.after ? [opts.after] : [];
        opts.after.unshift(function(){ opts.busy=0; });
            
        // allow shorthand overrides of width, height and timeout
        var cls = this.className;
        opts.width = parseInt((cls.match(/w:(\d+)/)||[])[1]) || opts.width;
        opts.height = parseInt((cls.match(/h:(\d+)/)||[])[1]) || opts.height;
        opts.timeout = parseInt((cls.match(/t:(\d+)/)||[])[1]) || opts.timeout;

        if ($cont.css('position') == 'static') 
            $cont.css('position', 'relative');
        if (opts.width) 
            $cont.width(opts.width);
        if (opts.height && opts.height != 'auto') 
            $cont.height(opts.height);

        var first = 0;
        $slides.each(function(i) { 
            $(this).css('z-index', els.length-i) 
        });
        
        $(els[first]).css('opacity',1).show(); // opacity bit needed to handle reinit case
        if ($.browser.msie) els[first].style.removeAttribute('filter');

        if (opts.fit && opts.width) 
            $slides.width(opts.width);
        if (opts.fit && opts.height && opts.height != 'auto') 
            $slides.height(opts.height);
        if (opts.pause) 
            $cont.hover(function(){this.cyclePause=1;}, function(){this.cyclePause=0;});

        var txFn = $.fn.cycle.transitions[opts.fx];
		txFn && txFn($cont, $slides, opts);
        
        $slides.each(function() {
            var $el = $(this);
            this.cycleH = (opts.fit && opts.height) ? opts.height : $el.height();
            this.cycleW = (opts.fit && opts.width) ? opts.width : $el.width();
        });

        if (opts.cssFirst)
            $($slides[first]).css(opts.cssFirst);

        if (opts.timeout) {
            // ensure that timeout and speed settings are sane
            if (opts.speed.constructor == String)
                opts.speed = {slow: 600, fast: 200}[opts.speed] || 400;
            if (!opts.sync)
                opts.speed = opts.speed / 2;
            while((opts.timeout - opts.speed) < 250)
                opts.timeout += opts.speed;
        }
        opts.speedIn = opts.speed;
        opts.speedOut = opts.speed;

 		opts.slideCount = els.length;
        opts.currSlide = first;
        opts.nextSlide = 1;

        // fire artificial events
        var e0 = $slides[first];
        if (opts.before.length)
            opts.before[0].apply(e0, [e0, e0, opts, true]);
        if (opts.after.length > 1)
            opts.after[1].apply(e0, [e0, e0, opts, true]);
        
        if (opts.click && !opts.next)
            opts.next = opts.click;
        if (opts.next)
            $(opts.next).bind('click', function(){return advance(els,opts,opts.rev?-1:1)});
        if (opts.prev)
            $(opts.prev).bind('click', function(){return advance(els,opts,opts.rev?1:-1)});

        if (opts.timeout)
            this.cycleTimeout = setTimeout(function() {
                go(els,opts,0,!opts.rev)
            }, opts.timeout + (opts.delay||0));
    });
};

function go(els, opts, manual, fwd) {
    if (opts.busy) return;
    var p = els[0].parentNode, curr = els[opts.currSlide], next = els[opts.nextSlide];
    if (p.cycleTimeout === 0 && !manual) 
        return;

    if (manual || !p.cyclePause) {
        if (opts.before.length)
            $.each(opts.before, function(i,o) { o.apply(next, [curr, next, opts, fwd]); });
        var after = function() {
            if ($.browser.msie)
                this.style.removeAttribute('filter');
            $.each(opts.after, function(i,o) { o.apply(next, [curr, next, opts, fwd]); });
            queueNext();
        };

        if (opts.nextSlide != opts.currSlide) {
            opts.busy = 1;
            $.fn.cycle.custom(curr, next, opts, after);
        }
        var roll = (opts.nextSlide + 1) == els.length;
        opts.nextSlide = roll ? 0 : opts.nextSlide+1;
        opts.currSlide = roll ? els.length-1 : opts.nextSlide-1;
    }
    
    function queueNext() {
        if (opts.timeout)
            p.cycleTimeout = setTimeout(function() { go(els,opts,0,!opts.rev) }, opts.timeout);
    }
};

// advance slide forward or back
function advance(els, opts, val) {
    var p = els[0].parentNode, timeout = p.cycleTimeout;
    if (timeout) {
        clearTimeout(timeout);
        p.cycleTimeout = 0;
    }
    opts.nextSlide = opts.currSlide + val;
    if (opts.nextSlide < 0) {
        opts.nextSlide = els.length - 1;
    }
    else if (opts.nextSlide >= els.length) {
        opts.nextSlide = 0;
    }
    go(els, opts, 1, val>=0);
    return false;
};

$.fn.cycle.custom = function(curr, next, opts, cb) {
    var $l = $(curr), $n = $(next);
    $n.css(opts.cssBefore);
    var fn = function() {$n.animate(opts.animIn, opts.speedIn, opts.easeIn, cb)};
    $l.animate(opts.animOut, opts.speedOut, opts.easeOut, function() {
        $l.css(opts.cssAfter);
        if (!opts.sync) fn();
    });
    if (opts.sync) fn();
};

$.fn.cycle.transitions = {
    fade: function($cont, $slides, opts) {
		$slides.not(':eq(0)').hide();
		opts.cssBefore = { opacity: 0, display: 'block' };
		opts.cssAfter  = { display: 'none' };
		opts.animOut = { opacity: 0 };
		opts.animIn = { opacity: 1 };
    },
    fadeout: function($cont, $slides, opts) {
		opts.before.push(function(curr,next,opts,fwd) {
			$(curr).css('zIndex',opts.slideCount + (fwd === true ? 1 : 0));
			$(next).css('zIndex',opts.slideCount + (fwd === true ? 0 : 1));
		});
		$slides.not(':eq(0)').hide();
		opts.cssBefore = { opacity: 1, display: 'block', zIndex: 1 };
		opts.cssAfter  = { display: 'none', zIndex: 0 };
		opts.animOut = { opacity: 0 };
    }
};

$.fn.cycle.ver = function() { return ver; };

// @see: http://malsup.com/jquery/cycle/lite/
$.fn.cycle.defaults = {
	animIn:        {},
	animOut:       {},
	fx:           'fade',
    after:         null, 
    before:        null, 
	cssBefore:     {},
	cssAfter:      {},
    delay:         0,    
    fit:           0,    
    height:       'auto',
	metaAttr:     'cycle',
    next:          null, 
    pause:         0,    
    prev:          null, 
    speed:         1000, 
    slideExpr:     null,
    sync:          1,    
    timeout:       4000 
};

})(jQuery);



jQuery.fn.cycle.defaults.speed = 750;
jQuery.fn.cycle.defaults.timeout = 3500; 

var mosaic_box_code = '<div class="mosaic_box" style="width:175px;height: 175px;float:left;"></div>';

/*
 *  NOW comes the action, here's the document.ready handler.  
 */

jQuery(document).ready(function(){
	jQuery('#xfader img:first-child').show();
	jQuery('#xfader').cycle();
	/*jQuery('.view-promo-product-brands .img-list ul').cycle();
	jQuery('div.view-dom-id-1').find(".img-list").jCarouselLite({
		auto:800,
		speed:1000,
		visible:4
	});
	*/
	
	jQuery('div.view-dom-id-1').find(".img-list").append(mosaic_box_code).append(mosaic_box_code).append(mosaic_box_code).append(mosaic_box_code).append(mosaic_box_code).append(mosaic_box_code).append(mosaic_box_code).append(mosaic_box_code).append(mosaic_box_code).append(mosaic_box_code).append(mosaic_box_code).append(mosaic_box_code);
	jQuery('div.view-dom-id-1').find(".img-list ul").addClass('mosaic_list').find("li").addClass('mosaic_li').find("img").addClass('mosaic_img');
	var bob = jQuery('div.view-dom-id-1').find(".img-list").mosaic({rotationSpeed:1500,popup:false});
});

/*
 auto slider for use with the brands page
*/

(function($){$.fn.jCarouselLite=function(o){o=$.extend({btnPrev:null,btnNext:null,btnGo:null,mouseWheel:false,auto:null,speed:200,easing:null,vertical:false,circular:true,visible:3,start:0,scroll:1,beforeStart:null,afterEnd:null},o||{});return this.each(function(){var b=false,animCss=o.vertical?"top":"left",sizeCss=o.vertical?"height":"width";var c=$(this),ul=$("ul",c),tLi=$("li",ul),tl=tLi.size(),v=o.visible;if(o.circular){ul.prepend(tLi.slice(tl-v-1+1).clone()).append(tLi.slice(0,v).clone());o.start+=v}var f=$("li",ul),itemLength=f.size(),curr=o.start;c.css("visibility","visible");f.css({overflow:"hidden",float:o.vertical?"none":"left"});ul.css({margin:"0",padding:"0",position:"relative","list-style-type":"none","z-index":"1"});c.css({overflow:"hidden",position:"relative","z-index":"2",left:"0px"});var g=o.vertical?height(f):width(f);var h=g*itemLength;var j=g*v;f.css({width:f.width(),height:f.height()});ul.css(sizeCss,h+"px").css(animCss,-(curr*g));c.css(sizeCss,j+"px");if(o.btnPrev)$(o.btnPrev).click(function(){return go(curr-o.scroll)});if(o.btnNext)$(o.btnNext).click(function(){return go(curr+o.scroll)});if(o.btnGo)$.each(o.btnGo,function(i,a){$(a).click(function(){return go(o.circular?o.visible+i:i)})});if(o.mouseWheel&&c.mousewheel)c.mousewheel(function(e,d){return d>0?go(curr-o.scroll):go(curr+o.scroll)});if(o.auto)setInterval(function(){go(curr+o.scroll)},o.auto+o.speed);function vis(){return f.slice(curr).slice(0,v)};function go(a){if(!b){if(o.beforeStart)o.beforeStart.call(this,vis());if(o.circular){if(a<=o.start-v-1){ul.css(animCss,-((itemLength-(v*2))*g)+"px");curr=a==o.start-v-1?itemLength-(v*2)-1:itemLength-(v*2)-o.scroll}else if(a>=itemLength-v+1){ul.css(animCss,-((v)*g)+"px");curr=a==itemLength-v+1?v+1:v+o.scroll}else curr=a}else{if(a<0||a>itemLength-v)return;else curr=a}b=true;ul.animate(animCss=="left"?{left:-(curr*g)}:{top:-(curr*g)},o.speed,o.easing,function(){if(o.afterEnd)o.afterEnd.call(this,vis());b=false});if(!o.circular){$(o.btnPrev+","+o.btnNext).removeClass("disabled");$((curr-o.scroll<0&&o.btnPrev)||(curr+o.scroll>itemLength-v&&o.btnNext)||[]).addClass("disabled")}}return false}})};function css(a,b){return parseInt($.css(a[0],b))||0};function width(a){return a[0].offsetWidth+css(a,'marginLeft')+css(a,'marginRight')};function height(a){return a[0].offsetHeight+css(a,'marginTop')+css(a,'marginBottom')}})(jQuery);
 
/*
 * mosaic gallery widget/plugin
 */

/////////////////////////////////
//jQuery Mosaic Gallery V1.0 ///
/////////////////////////////////
//
//DETAILS: 		HTTP://WWW.JQUERYMOSAICGALLERY.COM
//AUTHOR:			STEPHEN CUNNINGHAM
//TYPICAL USE: 	$("#your_div").picnmix();
//COPYRIGHT: 		(C) 2010 Steve Cunningham sjacunningham@gmail.com
//					Licensed under the MIT License:
//					http://www.opensource.org/licenses/mit-license.php
//
//HAVE FUN!

(function($){
		  
$.fn.mosaic = function(options) {

//////////////////////////////////////////////////
//INITIALISE

//SET DEFAULTS
	var defaults = {
		autoPopulate: true,
		rotationEffect: 'fade',
		rotationSpeed: 4000,
		pulse: false,
		popup: true
	};
//MERGE USER DEFINED AND DEFAULT OPTIONS
	var options = $.extend(defaults, options);
	
	
return this.each(function() {
	//Constrain function scope
	var obj = this;

	//Hide the photos
	$(".mosaic_img, ul", obj).hide();
	$("#nojavascript", obj).hide();
	//Override css - gracefull degregation failsafe incase javascript is not enabled
	$(obj).css("overflow","hidden");
	$(".mosaic_box", obj).css("display","block");
	var interval = '';

//////////////////////////////////////////////////
//AUTOPOPULATE
	//Populate each of the mosaic boxs with a picture
	if (options.autoPopulate) {
		$('.mosaic_box', obj).each(function(){
		
			$(".mosaic_list  .mosaic_img", obj).random(1).appendTo(this).show();
			
			var box_h = parseInt($(this).css('height'));
			var box_w = parseInt($(this).css('width'));
			var img = $(this).find('img');
				var img_w = img.attr('width');
				var img_h = img.attr('height');

				if ((img_w / box_w) > (img_h / box_h)){ //Aspect is landscape

						var ratio =  box_h  / img_h; // Get ratio for scaling image
						//img.css("height",  box_h ); // Set new height
						//img.css("width",  (Math.round(img_w * ratio))); // Scale width based on ratio

					}else{//aspect is portrate
					
						var ratio =  box_w  / img_w; // Get ratio for scaling image
						//img.css("width", box_w); // Set new height
						//img.css("height", (Math.round(img_h * ratio))); // Scale width based on ratio
					
					}
	
				//img_w = img_w * ratio;  // Reset width to match scaled image
				//img_h = img_h * ratio; // Reset height to match scaled image
			
				//Center image in box
				img_css = {
					left: (Math.round((box_w - img_w)/2)) + 'px',
					top: (Math.round((box_h - img_h)/2)) + 'px'
				};
				img.css(img_css);  

		});//End mosaic each function
		
		//$('ul li:empty').remove();//Remove the empty list items from the pic list
	
	}//End if autopopulate
	
//////////////////////////////////////////////////
//FADE
	//Start auto rotate
	if(options.rotationEffect == 'fade') {

		$.fn.mosaic.fade_in_out = function () {	
		
		//Select random box but not the last one and not one that is hovered over
		var mosaic_box = $('.mosaic_box:not(.mosaic_last_box):not(.mosaic_hover)', obj).random(1);
		$('.mosaic_box').removeClass('mosaic_last_box');
		mosaic_box.addClass('mosaic_last_box');
		
		//Swap its child image with a new one but not the last one	
		clear_old_img_css = {
					left: '0px',
					top: '0px',
					margin: '0px',
					height: 'auto',
					width: 'auto',
					display: 'none'
			};

		$('.mosaic_list li a:empty', obj).random(1).html(mosaic_box.find('img').addClass('mosaic_last_img').css(clear_old_img_css));
		$('.mosaic_list .mosaic_img:not(.mosaic_last_img)', obj).random(1).appendTo(mosaic_box).fadeIn('slow');		
		$('.mosaic_list .mosaic_img', obj).removeClass('mosaic_last_img');
			
			var box_h = parseInt(mosaic_box.css('height'));
			var box_w = parseInt(mosaic_box.css('width'));
			var img = mosaic_box.find('img');
				var img_w = img.attr('width');
				var img_h = img.attr('height');

				//alert(img.attr('src')+'    w:'+img_w+' b '+box_w+' ... h:'+img_h+' b '+box_h);
				
				if ((img_w / box_w) > (img_h / box_h)){ //Aspect is landscape

						var ratio =  box_h  / img_h; // Get ratio for scaling image
						//img.css("height",  box_h ); // Set new height
						//img.css("width",  (Math.round(img_w * ratio))); // Scale width based on ratio

					}else{//aspect is portrate
					
						var ratio =  box_w  / img_w; // Get ratio for scaling image
						//img.css("width", box_w); // Set new height
						//img.css("height", (Math.round(img_h * ratio))); // Scale width based on ratio
					
					}
	
				//img_w = img_w * ratio;  // Reset width to match scaled image
				//img_h = img_h * ratio; // Reset height to match scaled image
			
				//Center image in box
				img_css = {
					left: (Math.round((box_w - img_w)/2)) + 'px',
					top: (Math.round((box_h - img_h)/2)) + 'px'
				};
				
				img.css(img_css);  
		
		}
		interval = setInterval('jQuery.fn.mosaic.fade_in_out()',options.rotationSpeed);
	
	}//End if fade
	


	});//end return this.each(function() {	
		
	};
})( jQuery );

/**
*
* jQuery Random plugin
*
* @author   Michel Belleville <michel.belleville@gmail.com>
* @version  1.1.0
* @requires jQuery v1.3.2 or later
* @license  GPLv3 [http://www.gnu.org/licenses/gpl.html]
* 
* @description Picks element(s) at random in a selection.
* @param integer num (optional) number of elements to pick
* 
* Use :
* $('#whatever .you .like').random();
* $('.you_can_event select .more_than_one').random(10);
* 
*/
(function($) {
jQuery.fn.random = function(num) {
 num = parseInt(num);
 if (num > this.length) return this.pushStack(this);
 if (! num || num < 1) num = 1;
 var to_take = new Array();
 this.each(function(i) { to_take.push(i); });
 var to_keep = new Array();
 var invert = num > (this.length / 2);
 if (invert) num = this.length - num;
 for (; num > 0; num--) {
   for (var i = parseInt(Math.random() * to_take.length); i > 0; i--)
     to_take.push(to_take.shift());
   to_keep.push(to_take.shift());
 }
 if (invert) to_keep = to_take;
 return this.filter(function(i) { return $.inArray(i, to_keep) != -1; });
};
}) (jQuery);;

