jQuery(function() {

    for(var bv in jQuery.browser)
    {
        jQuery('body').addClass(bv);
        
        if (bv == "msie")
        {
            jQuery('.button').wrap('<div class="button" />').parent().append('<span />');
        }
        break;
    }

    jQuery("a[rel^='prettyPhoto']").prettyPhoto({ theme: 'light_rounded' });

    /* Clever input */
    jQuery('.clever-input')
	    .live('click', function() {
	        if (jQuery(this).val() == jQuery(this).attr('title')) {
	            jQuery(this).val('');
	        } else {
	            if (jQuery(this).val() == '') {
	                jQuery(this).val(jQuery(this).attr('title'));
	            }
	        }
	    })
	    .live('blur', function() {
	        jQuery(this).trigger('click');
	    });
    
    /* basket toggle */
    jQuery('#site-head .basket a.toggle').toggle(
        function(){ 
            jQuery(this).parent().addClass('open').find('.items').fadeIn(150);
        }, 
        function(){
            jQuery(this).parent().removeClass('open').find('.items').fadeOut(150);
        }
    );
    jQuery('#site-head .basket.open').live('mouseleave', function(){ jQuery('#site-head .basket a.toggle').trigger('click'); });
    
    /* Fancy selects */
    jQuery('body:not(.ie7) select.fancy').FancySelect();
        
    /* Preload the processing-spinner.gif */
    var img = new Image();
    img.src = "/assets/visual/processing-spinner.gif";

    jQuery('body.msie .product-list ul li:nth-child(4n)').css('margin-right',0);
});

/*
 * ImageRotator 1.0.0 - Javascript Image Rotator
 *
 * Copyright: Skylight Media Ltd.
 *
 * Author: Skylight Media Ltd.
 *
 * $Date: 24-06-2010
 *
 *	ChangeLog:
 *  
 * Unauthorized use of this script is not permitted, please contact Skylight Media Ltd. to request use of this script
 */
(function($)
{
    $.fn.ImageRotator = function(options)
    {
        var settings = {
            items_count: 0,
            OVERLAY_FADE_TIME: 1000,
            IMAGE_FADE_TIME: 1000,
            IMAGE_WAIT_TIME: 10000
        };

		/* extend/change options */
		options = options || {};
    	$.extend(settings, options);
    	
		return this.each(function()
		{
		    /* Get container */
		    var $cont = $(this);
		    
		    settings.items_count = $('a', $cont).length;
						
			/* add z-index */
			$('a', $cont).each(function(indx, value){ $(this).css("z-index", settings.items_count - indx); });
			
			/* add overlay */
			$cont.append('<div class="overlay" />').find('.overlay').css("z-index", settings.items_count + 1);
			
			var img = new Image();
            img.onload = function(){
                $cont.find('.overlay').fadeOut(settings.OVERLAY_FADE_TIME);
                if (settings.items_count > 1) {
                    setInterval(function() {
                        Rotate();
                    }, settings.IMAGE_WAIT_TIME);
                }
            };
            img.src = $('a:eq(0) img', $cont).attr('src');
            
            function Rotate(){
                i = 0;
                $('a:eq(0)', $cont).fadeOut(settings.IMAGE_FADE_TIME, function(){
                    jQuery(this).nextAll().each(function(){ jQuery(this).css({ "z-index": settings.items_count - (i++) }) });
                    jQuery(this)
                        .css({ "z-index": settings.items_count - (i++) }).show()
                        .parent().append(jQuery(this));
                })
            }
		});
	}
})(jQuery);

function CreateRotator(o)
{
    /* How many pages do we need */
    pages = jQuery(o.item_type, o.el).size();
    
    if (pages <= 1)
        return;
    
    if (pages > o.items_per_page){
        jQuery(o.el).append('<div class="pages" />');
    }
    pages = Math.ceil(pages / o.items_per_page);
            
    for(i=1;i<=pages;i++){
        jQuery('.pages', o.el).append('<span class="btn page '+i+'"></span>'); /*Append a page button*/
    }    
    
    auto_value = 2500; speed_value = 1100;
        
    jQuery(o.el).addClass('jCarousel')
        .data('page', 0)
        .data('items', jQuery(o.item_type, o.el).size())
        .jCarouselLite({
            item_type: o.item_type,
            visible: o.items_per_page,
            scroll: o.items_per_page,
            auto: auto_value,
            speed: speed_value,
            animation: o.animation ? o.animation : 'slide',
            /*easing: 'easeOutQuint',*/
            btnGo: jQuery('.pages .btn.page', o.el)
        });
}

(function($)
{
    $.fn.FancySelect = function(settings)
    {
        var o = {
        };

		/* extend/change options */
		settings = settings || {};
    	$.extend(o, settings);
    	
		return this.each(function()
		{
		    /* Get select */
		    var $select = $(this);
		    		    		    
		    /* add html and options */
            $select.after('<div class="fancy-select"><span class="selected"><span /></span><div class="items" /></div>');
            fancy_select_opts = $select.next('.fancy-select').append($select).find('select').hide().end().find('div');
            jQuery('option', $select).each(function(i, option){
                if (jQuery(option).is(':selected')){
                    fancy_select_opts.prev('span.selected').find('span').html(jQuery(option).html());
                }
                fancy_select_opts.append('<span rel="'+jQuery(option).val()+'">'+jQuery(option).html()+'</span>');
            });
            
            /* option select event */
            jQuery(fancy_select_opts.closest('.fancy-select')).delegate('div.items > span','click', function(e){
                $this = jQuery(e.target);
                $this.closest('div').prev('span.selected').find('span').html($this.html()).attr('rel', $this.attr('rel'));
                $this.closest('.fancy-select').find('select').find("option[value='"+$this.attr('rel')+"']").attr('selected', 'selected').end().trigger('change');
            });
            
            /* select opener */
            jQuery(fancy_select_opts.closest('.fancy-select')).toggle(
                function(){
                    if (!jQuery(this).hasClass('open')){
                        if (!jQuery.browser.msie){
                            to_height = jQuery(this).addClass('open').find('div').css('visibility','hidden').show().height();
                            jQuery(this).find('div').css({ height:'0px', visibility:'inherit' }).animate({ height: to_height }, 150, function(){ jQuery(this).attr('style','').show() });
                        }else {
                            jQuery(this).find('div').show();
                        }
                    }
                },
                function(){
                    if (!jQuery.browser.msie){
                        jQuery(this).removeClass('open').find('div').animate({ height: 0 }, 150, function(){ jQuery(this).attr('style','').hide(); });
                    }else{
                        jQuery(this).find('div').hide();
                    }
                }
            ).mouseleave(function(e){
                if (jQuery(this).hasClass('open')){
                    jQuery(this).trigger('click');
                }
            });
            
            /* on select contents change */
            $select.bind('contentsChanged', function(e){
		        $this = $(e.target);
		        $this.prev('div').empty().end().prevAll('.selected').html('<span />');
		        jQuery('option', $this).each(function(i, option){
                    if (jQuery(option).is(':selected')){
                        fancy_select_opts.prev('span.selected').find('span').html(jQuery(option).html());
                    }
                    fancy_select_opts.append('<span rel="'+jQuery(option).val()+'">'+jQuery(option).html()+'</span>');
                });
		    });
		    
		});
    }
})(jQuery);

/* Modified jCarousel */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(5($){$.1g.1h=5(o){o=$.1i({l:r,L:\'1j\',M:\'1k\',s:\'1l\',N:r,D:1m,12:r,1n:13,t:3,14:0,15:1,O:r,A:r},o||{});q 7.E(5(){o.M=$($(o.s,7).1o(0)).16()[0].1p.1q();m c=F,P=o.Q?"R":"u",S=o.Q?"w":"x";m d=$(7),n=$(o.M+\':1r(.1s)\',d),T=$(o.s,n),G=T.17(),v=o.t;m e=$(o.s,n),U=e.17(),8=o.14;d.4("1t","t");e.4({18:"19",1u:o.Q?"1a":"u"});n.4({1v:"0",1w:"0",V:"1b","1x-1y-1z":"1a","z-B":"1"});d.4({18:"19",V:"1b","z-B":"2",u:"1A"});m f=x(e);m g=f*U;m h=f*v;e.4({x:e.x(),w:e.w()});n.4(S,g+"H").4(P,-(8*f));6(o.L=="1c"){m j=w(e);e.4({V:\'1B\',R:0,u:0});d.4({x:f+"H",w:j+"H"});T.E(5(a,b){$(7).4(\'z-B\',G-a)})}I{d.4(S,h+"H")}m k=r;6(o.l){$.E(o.l,5(i,a){$(a).1C(5(){W();q X(i*o.t)})});p(o.l[0]).Y(\'y\').Z().10(\'y\')}6(o.N)W();6(o.C)J();5 W(){1D(k);k=1E(5(){X(8+o.15)},o.N+o.D)}5 K(){q e.1d(8).1d(0,v)};5 J(){$9=n.1F(o.s+\':1e(\'+8+\') a\').1G(\'1H\');6($9.1I(\'|\')>-1){$9=$9.1J(\'|\')}I{$9=1K($9)}o.C.1L(\'<b>\'+$9[0]+\'</b>\');6($9.1M>1){o.C.1f($9[1])}};5 X(a){6(!c){6(o.O)o.O.11(7,K());6(a<0||a>U-v){8=0}I 8=a;c=13;6(o.L=="1c"){i=0;$(o.s+\':1e(0)\',n).1N(o.D,5(){p(7).1O().E(5(){p(7).4({"z-B":G-(i++)})});p(7).4({"z-B":G-(i++)}).1P().16().1f(p(7));6(o.A)o.A.11(7,K());6(o.l)p(o.l[8/o.t]).Y(\'y\').Z().10(\'y\');6(o.C)J();c=F})}I{n.1Q((P=="u"?{u:-(8*f)}:{R:-(8*f)}),o.D,o.12,5(){6(o.A)o.A.11(7,K());6(o.l)p(o.l[8/o.t]).Y(\'y\').Z().10(\'y\');6(o.C)J();c=F})}}q F}})};5 4(a,b){q 1R($.4(a[0],b))||0};5 x(a){q a[0].1S+4(a,\'1T\')+4(a,\'1U\')};5 w(a){q a[0].1V+4(a,\'1W\')+4(a,\'1X\')}})(p);',62,122,'||||css|function|if|this|curr|text||||||||||||btnGo|var|item_cont||jQuery|return|null|item_type|visible|left||height|width|active||afterEnd|index|useText|speed|each|false|tl|px|else|setText|vis|animation|item_container|auto|beforeStart|animCss|vertical|top|sizeCss|tItem|itemLength|position|SetAutoScrollInterval|go|addClass|siblings|removeClass|call|easing|true|start|scroll|parent|size|overflow|hidden|none|relative|rotate|slice|eq|append|fn|jCarouselLite|extend|slide|ul|li|200|circular|get|tagName|toLowerCase|not|pages|visibility|float|margin|padding|list|style|type|0px|absolute|click|clearInterval|setInterval|find|attr|title|indexOf|split|Array|html|length|fadeOut|nextAll|show|animate|parseInt|offsetWidth|marginLeft|marginRight|offsetHeight|marginTop|marginBottom'.split('|'),0,{}));


/* json2.js 
 * 2008-01-17
 * Public Domain
 * No warranty expressed or implied. Use at your own risk.
 * See http://www.JSON.org/js.html
*/
if(!this.JSON){JSON=function(){function f(n){return n<10?'0'+n:n;}
Date.prototype.toJSON=function(){return this.getUTCFullYear()+'-'+
f(this.getUTCMonth()+1)+'-'+
f(this.getUTCDate())+'T'+
f(this.getUTCHours())+':'+
f(this.getUTCMinutes())+':'+
f(this.getUTCSeconds())+'Z';};var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};function stringify(value,whitelist){var a,i,k,l,r=/["\\\x00-\x1f\x7f-\x9f]/g,v;switch(typeof value){case'string':return r.test(value)?'"'+value.replace(r,function(a){var c=m[a];if(c){return c;}
c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+
(c%16).toString(16);})+'"':'"'+value+'"';case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
if(typeof value.toJSON==='function'){return stringify(value.toJSON());}
a=[];if(typeof value.length==='number'&&!(value.propertyIsEnumerable('length'))){l=value.length;for(i=0;i<l;i+=1){a.push(stringify(value[i],whitelist)||'null');}
return'['+a.join(',')+']';}
if(whitelist){l=whitelist.length;for(i=0;i<l;i+=1){k=whitelist[i];if(typeof k==='string'){v=stringify(value[k],whitelist);if(v){a.push(stringify(k)+':'+v);}}}}else{for(k in value){if(typeof k==='string'){v=stringify(value[k],whitelist);if(v){a.push(stringify(k)+':'+v);}}}}
return'{'+a.join(',')+'}';}}
return{stringify:stringify,parse:function(text,filter){var j;function walk(k,v){var i,n;if(v&&typeof v==='object'){for(i in v){if(Object.prototype.hasOwnProperty.apply(v,[i])){n=walk(i,v[i]);if(n!==undefined){v[i]=n;}}}}
return filter(k,v);}
if(/^[\],:{}\s]*$/.test(text.replace(/\\./g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof filter==='function'?walk('',j):j;}
throw new SyntaxError('parseJSON');}};}();}

