//Function to change images
var imageURL = "images/NCHR_makeover_Banner.jpg";//blackfinn//

if (document.images) {
     var ad1 = new Image();
     ad1.src = "images/NCHR_makeover_Banner.jpg";//blackfinn//

     var ad2 = new Image();
     ad2.src = "images/WWC-banner-MCFK.jpg";//makeachange//
	 
	 var ad3 = new Image();
     ad3.src = "images/MsMs_960.jpg";
	 
	 var ad4 = new Image();
     ad4.src = "images/levine-childrens-hospital.jpg";
	 
	 var ad5 = new Image();
     ad4.src = "images/whisky-river-ad.jpg";
	 
	 var ad6 = new Image();
     ad4.src = "images/foursquare-ad.jpg";
	 
	 var ad7 = new Image();
     ad4.src = "images/homepageTOM.jpg";

}

function changeImage() {
     if (document.images) {
     		if (imageURL == "images/whisky-river-ad.jpg") imageURL = "images/levine-childrens-hospital.jpg";
		  	else if (imageURL == "images/levine-childrens-hospital.jpg") imageURL = "images/MsMs_960.jpg";
		  	else if (imageURL == "images/MsMs_960.jpg") imageURL = "images/WWC-banner-MCFK.jpg";
		 	else if (imageURL == "images/WWC-banner-MCFK.jpg") imageURL = "images/NCHR_makeover_Banner.jpg";
			else if (imageURL == "images/NCHR_makeover_Banner.jpg") imageURL = "images/homepageTOM.jpg";
			else if (imageURL == "images/homepageTOM.jpg") imageURL = "images/foursquare-ad.jpg";
			else if (imageURL == "images/foursquare-ad.jpg") imageURL = "images/whisky-river-ad.jpg";
          	else imageURL = "images/whisky-river-ad.jpg";
         document.myImage.src = imageURL;
     }
}


function changeImage1() {
     if (document.images) {
          	if (imageURL == "images/whisky-river-ad.jpg") imageURL = "images/foursquare-ad.jpg";
		  	else if (imageURL == "images/foursquare-ad.jpg") imageURL = "images/homepageTOM.jpg";
		  	else if (imageURL == "images/homepageTOM.jpg") imageURL = "images/NCHR_makeover_Banner.jpg";
			else if (imageURL == "images/NCHR_makeover_Banner.jpg") imageURL = "images/WWC-banner-MCFK.jpg";
		 	else if (imageURL == "images/WWC-banner-MCFK.jpg") imageURL = "images/MsMs_960.jpg";
			else if (imageURL == "images/MsMs_960.jpg") imageURL = "images/levine-childrens-hospital.jpg";
			else if (imageURL == "images/levine-childrens-hospital.jpg") imageURL = "images/whisky-river-ad.jpg";
          	else imageURL = "images/levine-childrens-hospital.jpg";
         document.myImage.src = imageURL;
     }
}
//End of Function to change images


/*
 *  Plugin of Simple Never End Spin Carousel
 *  ----------------------------------------
 *  12/03/2009 - Westfield 2009
 *  version: 0.5
 *  Author: Agus Daud
 *  Email: agusdaud@gmail.com
 *  ----------------------------------------
 *
 *  The simple mod of the current carousel
 *  by replacing the left pixel once it reach most left or right
 *  so it look like unlimited spinned.
 *  Note: for the countless spin the number item show need
 *  to be smaller then total number in carousel
 *
 */
 
 

(function($) {

    jQuery.fn.premiumCarousel = function (options) {

        var opts = jQuery.extend({}, jQuery.fn.premiumCarousel.defaults, options);

        // Core function
        return this.each(function() {

            var $this = jQuery(this);
            var o = jQuery.meta ? jQuery.extend({}, opts, $this.data()) : opts;

            var carouselSpinOriginalSize = $this.find("li:not(.border)").size();
            var carouselSpinShow = o.carouselItemShow;
            var carouselSpinWidth = o.carouselItemWidth;
            var carouselSpinValue = 0;
            var carouselMaxSize = carouselSpinOriginalSize - carouselSpinShow;
            var anime = false;

            if (o.carouselLoop == 'yes') {

                if (carouselSpinOriginalSize <= carouselSpinShow) {
                    alert('Never End Spin Carousel is not going to work the total number of item need to be bigger than total view item');
                }

                // Automatic insert the clone of other item to make the never end spinned trick works
                for (i=0; i <carouselSpinShow; i++) {
                    copyComp = $this.find("li:not(.border):eq("+i+")");
                    copyCompBorder = $this.find("li.border:eq("+i+")");
                    $this.find("li:last").after(copyComp.clone());
                    $this.find("li:last").after(copyCompBorder.clone());
                }

            }

            var carouselSpinSize =  $this.find("li:not(.border)").size();
            var carouselValue = 0;
            var maxSpinSize = carouselSpinSize - carouselSpinShow;

            $this.parent().css("width",carouselSpinShow * carouselSpinWidth-2);
            $this.css({width: (carouselSpinSize*carouselSpinWidth)+"px"});
            resetSpinCarousel = carouselSpinWidth * maxSpinSize ;

            // insert the left and right button
            $this.parent().parent().after('<div class="carousel-left-button" id="carousel-spin-left-button"><div class="alpha-container"></div><a href="#" class="carousel-button" onclick="changeImage();">left-button</a></div>');
            $this.parent().parent().after('<div class="carousel-right-button" id="carousel-spin-right-button"><div class="alpha-container"></div><a href="#" class="carousel-button" onclick="changeImage1();">right-button</a></div>');

            if (o.carouselLoop == 'no') {
                jQuery.fn.premiumCarousel.hideCarouselButton(carouselMaxSize, carouselSpinWidth);
            }

            jQuery("#carousel-spin-right-button").click(function() {

                carouselSpinValue =  parseFloat($this.css("left"),10);
                if (o.carouselLoop != 'yes') {

                }
                if ((carouselSpinValue > (carouselSpinWidth * carouselMaxSize * -1)) && (anime == false) || (o.carouselLoop == 'yes' && anime == false)) {
                        anime = true;
                        $this.stop().animate({
                            left: "-=302px"
                        }, 700, function() {
                            anime = false;
                            carouselValue =  parseFloat($this.css("left"),10);
                            if (resetSpinCarousel+carouselValue == 0 && o.carouselLoop == 'yes') {
                               $this.css("left","0");
                            } else if (o.carouselLoop == 'no') {
                               jQuery.fn.premiumCarousel.hideCarouselButton(carouselMaxSize, carouselSpinWidth);

                            }
                        });

                }
                return false;
            });

            jQuery("#carousel-spin-left-button").click(function() {

                carouselSpinValue =  parseFloat($this.css("left"),10);
                if (carouselSpinValue == 0 && o.carouselLoop == 'yes') {
                    $this.css("left",0-resetSpinCarousel);
                }

                if (((carouselSpinValue < 0 ) && (anime == false)) || (o.carouselLoop == 'yes' && anime == false)) {
                        anime = true;
                        $this.stop().animate({
                            left: "+=302px"
                        }, 700, function() {
                            anime = false;
                            if (o.carouselLoop == 'no') {
                                jQuery.fn.premiumCarousel.hideCarouselButton(carouselMaxSize ,carouselSpinWidth);
                            }
                        });

                }

                return false;

             });

            if (o.carouselGrowth == 'yes') {
                $this.find("li .cont").hover(function() {
                    if (jQuery(this).parent().parent().attr("class") != "static") {
                        jQuery(this).parent().parent().find("div.carousel-container").stop().animate({
                            top: "0px"
                        }, 700);
                        jQuery(this).parent().find(".hover-image").stop().css({
                            display: "block"
                        }).fadeTo("slow", 1);
                    }
                },function() {
                    if (jQuery(this).parent().parent().attr("class") != "static") {
                        jQuery(this).parent().parent().find("div.carousel-container").stop().animate({
                            top: "0px"
                        }, 700);
                        jQuery(this).parent().find(".hover-image").stop().fadeTo("slow", 0);
                    }
                });
             }

        });

    };

    jQuery.fn.premiumCarousel.hideCarouselButton  = function(maxSize,carouselWidth) {

        carouselValue =  parseFloat(jQuery("#carousel-list").css("left"),10);

        if ((maxSize) == 0) {
            jQuery(".carousel-left-button a").hide();
            jQuery(".carousel-right-button a").hide();
        } else if ((carouselValue) == 0) {
            jQuery(".carousel-left-button a").hide();
            jQuery(".carousel-right-button a").show();
        } else if ((carouselValue) == (carouselWidth * maxSize * -1)) {
            jQuery(".carousel-right-button a").hide();
            jQuery(".carousel-left-button a").show();
        } else {
            jQuery(".carousel-right-button a").show();
            jQuery(".carousel-left-button a").show();
        }

        return true;

    };

    jQuery.fn.premiumCarousel.defaults = {
        carouselItemShow : 4,
        carouselItemWidth : 302,
        carouselLoop : 'yes',
        carouselGrowth: 'yes'
    };

})(jQuery);
