/**
 * Westfield 2008
 * @author Agus Daud
 * 
 */

 
jQuery.ui.accordion.animations.premiumslide = function(options) {
    this.slide(options, {
            easing: options.down ? "swing" : "swing",
            duration: options.down ? 700 : 600
    });
}; 
 
jQuery(document).ready(function() {

	jQuery('ul#homeacc').accordion({
		active: 1,
		header : "div.hdr",
		animated : "premiumslide",
		autoHeight: true
	});
	
	//Dummy function it will replace by the real one later
	jQuery('#SSCcategory-styleIt').toggle(function() {
		jQuery('#SSIcategory-styleIt').show();
	},function() {
		jQuery('#SSIcategory-styleIt').hide();
	});
	
	jQuery("div.cont .img .hover-image").css({opacity: 0});
	jQuery(".westfield-logo-layer").css({opacity: 0});
	
	jQuery("#carousel ul 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: "80px"
			}, 700);
			jQuery(this).parent().find(".hover-image").stop().fadeTo("slow", 0);
		}
	});
	
	jQuery(".westfield-giftcard-logo a").mouseover(function() {
		jQuery(this).parent().find(".westfield-logo-layer")
		.stop()
		.css({
			display: "block"
		})
		.animate({top: "-63px", opacity: 1},500);
	}).mouseout(function() {
		jQuery(this).parent().find(".westfield-logo-layer").stop().animate({top: "-80px", opacity: 0},500)
    .css({
			display: "none"
		});
  });
	
	
	// Simple Carousel
	var carouselShow = 3;
	var carouselWidth = 227;
	var carouselValue = 0;
	var carouselSize = jQuery("#carousel-list li .cont").size();
	var anime = false;
	var maxSize = carouselSize - carouselShow;
	
	function hideCarouselButton() {
		
		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();
		}
		
	}
	
	hideCarouselButton();
	
	jQuery("#carousel-list").css({width: (carouselSize*carouselWidth)+"px"});
	
	jQuery(".carousel-right-button").click(function() {
		carouselValue =  parseFloat(jQuery("#carousel-list").css("left"),10);
		
		if ((carouselValue > (carouselWidth * maxSize * -1)) && (anime == false)) {
			anime = true;
			jQuery("#carousel-list").stop().animate({
				left: "-=227px"
			}, 700, function() {
				anime = false;
				hideCarouselButton();
			});
			
		}
		
		return false;
		
	});
	
	jQuery(".carousel-left-button").click(function() {
		carouselValue =  parseFloat(jQuery("#carousel-list").css("left"),10);
		
		if ((carouselValue < 0 ) && (anime == false)) {
			anime = true;
			jQuery("#carousel-list").stop().animate({
				left: "+=227px"

			}, 700, function() {
				anime = false;
				hideCarouselButton();
			});
		}
		
		return false;
	});


});
