jQuery(function() {

    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');
	    });

    if (jQuery.browser.msie) {
        jQuery('#site-head .nav li:first, #site-head .nav li:last').append('<div class="ie-corner" />');
        jQuery('#site-main .side .panel div.top-bar').append('<span class="left" /><span class="right" />');
    }

    jQuery('#site-head .basket a.toggle').live('click', function() {
        if (jQuery('#site-head .basket .items').is(":hidden")) {
            jQuery('#site-head .basket .items').css({ height: 'auto' }).stop().slideDown(250);
        } else {
            jQuery('#site-head .basket .items').stop().slideUp(250);
        };
    });

    // Preload the processing-spinner.gif
    var img = new Image();
    img.src = "/assets/visual/processing-spinner.gif";
    
    

});


/* Init Image rotator */
function InitImageRotator() {

    jQuery('.imagerotator').TabRotator();
    return;
    
    images = jQuery('.imagerotator a').show();
    i = 0;
    jQuery('.imagerotator a').each(function() {
        jQuery(this).css("z-index", images.length - i);
        i++;
    });
    jQuery('.imagerotator a .overlay').css("z-index", images.length + 1);

    var img = new Image();
    img.onload = function() {
        jQuery('.imagerotator a .overlay').fadeOut(1000);
        if (images.length > 1) {
            setInterval(function() {
                i = 0;
                img = jQuery('.imagerotator a:eq(0)').fadeOut(600, function() {
                    jQuery(this)
                    .nextAll().each(function() { jQuery(this).css({ "z-index": images.length - (i++) }) })
                    .end().css({ "z-index": images.length - (i++) }).show()
                    .parent().append(jQuery(this));
                });
            }, 5000);
        }
    };
    img.src = jQuery('.imagerotator a:eq(0) img').attr('src');
}

/*
 * 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: 5000
        };

		/* 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);

/*
 * TabRotator 1.0.0 - Javascript Tab 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.TabRotator = function(options)
    {
        var settings = {
            BUTTONS_CLICK_TIMEOUT : null,
            BUTTONS_HOVER_DELAY : 400,
            BUTTONS_OPACITY_START : 0.2,
            BUTTONS_OPACITY_END : 0.8,
            BUTTONS_OPACITY_DURATION : 250,
            ROTATE_INTERVAL : 3000,
            ROTATE_INTERVAL_SPEEDY : 750,
            ROTATE_SPEED : 500,
            ITEMS_COUNT : 0,
            ROTATOR_TIMER : null,
            SCROLL_COUNT : 0,
            ALLOW_SCROLL : true,
            SPEEDY: false,
            INVERSE : false,
            IMAGE_FADE_DURATION : 600,
            TAB_SIZE : 74
        };

		/* extend/change options */
		options = options || {};
    	$.extend(settings, options);
    	
		return this.each(function()
		{
			var $cont = $(this);
			
			/* Get container */
			$cont.addClass("tab-rotator");
			
			/* Get count and set scroll count to end */
    	    settings.ITEMS_COUNT = jQuery('.text ul li', $cont).length;
    	    settings.SCROLL_COUNT = settings.ITEMS_COUNT;
    	    
    	    /* Append overlay */
    	    jQuery('.images', $cont).prepend('<div class="overlay" />');
    	    
    	    /* Append buttons */
    	    jQuery('.text', $cont).append('<div class="scroll-btn prev"><span /></div><div class="scroll-btn next"><span /></div>')
    	        .find(".scroll-btn").css({ opacity: settings.BUTTONS_OPACITY_START, height: settings.TAB_SIZE + "px" });
    	        
    	    /* Text container hover */
    	    jQuery('.text', $cont).hover(function() {
                    clearInterval(settings.ROTATOR_TIMER);
                    settings.ALLOW_SCROLL = false;
                }, function() {            
                    clearInterval(settings.ROTATOR_TIMER);
                    settings.ROTATOR_TIMER = setInterval(RotateTextPanel, settings.ROTATE_INTERVAL);
                    settings.ALLOW_SCROLL = true;
                }
            );
            
            /* Button hover + click */
            jQuery('.text .scroll-btn', $cont).hover(
                function(){
                    jQuery(this).stop().fadeTo(settings.BUTTONS_OPACITY_DURATION, settings.BUTTONS_OPACITY_END);
                    settings.SPEEDY = true;
                    clearInterval(settings.ROTATOR_TIMER);
                    settings.ALLOW_SCROLL = false;
                    settings.INVERSE = jQuery(this).hasClass("prev");
                    
                    settings.BUTTONS_CLICK_TIMEOUT = setTimeout(function(){
                        settings.ALLOW_SCROLL = true;
                        RotateTextPanel();
                        settings.ROTATOR_TIMER = setInterval(RotateTextPanel, settings.ROTATE_INTERVAL_SPEEDY);
                        clearTimeout(settings.BUTTONS_CLICK_TIMEOUT);
                    }, settings.BUTTONS_HOVER_DELAY);                    
                }, 
                function(){
                    jQuery(this).stop().fadeTo(settings.BUTTONS_OPACITY_DURATION, settings.BUTTONS_OPACITY_START);
                    settings.SPEEDY = false;
                    settings.ALLOW_SCROLL = true;
                    settings.INVERSE = false;
                    clearInterval(settings.ROTATOR_TIMER);
                    clearTimeout(settings.BUTTONS_CLICK_TIMEOUT);
                }
            ).click(function(){
                clearTimeout(settings.BUTTONS_CLICK_TIMEOUT);
                settings.ALLOW_SCROLL = false;
                jQuery('.text li a:eq('+ (settings.SCROLL_COUNT + (settings.INVERSE ? 0 : +3)) +')', $cont).trigger('click');
            });
            
            /* Text links click */
            jQuery('.text li a', $cont).click(function(e){
                e.preventDefault();
                jQuery(this).closest('li').addClass("active").siblings().removeClass("active");
                
                indx = jQuery('.text li a', $cont).index(jQuery(this));
                jQuery('.images .overlay', $cont).show().css({"z-index": 100, "opacity": 0.4}).fadeOut(settings.IMAGE_FADE_DURATION);
                jQuery('.images a:eq(' + indx + ')', $cont).css("z-index", 99).siblings().not('.overlay').css("z-index", 1);
            });
    	    
    	    /* Start rotator */
    	    RotateTextPanel();
    	    settings.ROTATOR_TIMER = setInterval(RotateTextPanel, settings.ROTATE_INTERVAL);
			
			function RotateTextPanel() {
                if (settings.ALLOW_SCROLL)
                {   
                    if (settings.SCROLL_COUNT >= (jQuery('.text ul li', $cont).length-4) && settings.SPEEDY && !settings.INVERSE) return;
                    
                    if (settings.SCROLL_COUNT >= (jQuery('.text ul li', $cont).length-4) && !settings.SPEEDY) {
                        /* At the end of the scroll, see if we need to loop through more images */
                        indx = jQuery('.text ul li', $cont).index(jQuery('.text ul li.active', $cont));
                        if (indx < (settings.ITEMS_COUNT-1) && indx > -1)
                        {
                            jQuery('.text li a:eq('+ (indx+1) +')', $cont).trigger('click');
                            return;
                        }
                        
                        jQuery('.text ul', $cont).animate({ top: "0" }, settings.ROTATE_SPEED);
                        settings.SCROLL_COUNT = 0;
                        jQuery('.text li a:eq(0)', $cont).trigger('click');
                        return;
                    }
                    
                    if (settings.SCROLL_COUNT == 0 && settings.INVERSE) return;                    

                    jQuery('.text ul', $cont).animate({ top: (settings.INVERSE ? "+=" : "-=") + settings.TAB_SIZE }, settings.ROTATE_SPEED);
                    settings.INVERSE ? (settings.SCROLL_COUNT = settings.SCROLL_COUNT-1) : (settings.SCROLL_COUNT = settings.SCROLL_COUNT+1);
                    
                    if (!settings.SPEEDY)
                    {
                        jQuery('.text li a:eq('+ settings.SCROLL_COUNT +')', $cont).trigger('click');
                    }
                }
            }		
		});		
	}
})(jQuery);
