/*
 * ScrollToElement 1.0
 * Copyright (c) 2009 Lauri Huovila, Neovica Oy
 *  lauri.huovila@neovica.fi
 *  http://www.neovica.fi
 *  
 * Dual licensed under the MIT and GPL licenses.
 */

(function($) {
    $.scrollToElement = function( $element, speed ) {

        speed = speed || 750;

        $("html, body").animate({
            scrollTop: $element.offset().top,
            scrollLeft: $element.offset().left
        }, speed);
        return $element;
    };

    $.fn.scrollTo = function( speed ) {
        speed = speed || "normal";
        return $.scrollToElement( this, speed );
    };
})(jQuery);


$(function() {
	$("#mycarousel li").each( function() {
		$(this).click( function	() {
			$("#mycarousel li").css("border","1px solid #ffffff");
			$("#mycarousel li div.name a").css("color","#373833");
			$(this).css("border","1px solid #e6e6e6");
			jQuery("a",this).css("color","#000000");
			/*$(".item-image").load(jQuery("div.item-id",this).html().toLowerCase() + ".html .item-image");*/
			
			$("a#scMainImage").attr("href",jQuery("div.item-full-image",this).html());
			$("a#scMainImage img").attr("src",jQuery("div.item-main-image img",this).attr("src"));
			$("a.scMainImgLnk").attr("href",jQuery("div.item-full-image",this).html());
			$("a.scMainImgLnk img").attr("src",jQuery("div.item-main-image-icon img",this).attr("src"));
			
			jQuery("div.item-insets span.hidden-inset",this).each(function(i){
				$("div#scPage-insets a:nth-child(" + (i+2) + ") img").attr("src",jQuery("img",this).attr("src"));								
				$("div#scPage-insets a:nth-child(" + (i+2) + ")").attr("href",jQuery("div",this).html());
			});

			if (jQuery("div.sale-price",this).html()) {
				$(".item-info-price").html(jQuery("div.price",this).html() + '<img width="10" height="1" border="0" src="http://ep.yimg.com/ca/Img/trans_1x1.gif"/><span class="item-info-saleprice">' + jQuery("div.sale-price",this).html() + "</span>");
				$("#pitSalePriceBx").html("$" + jQuery("div.sale-price",this).html().match(/\d+\.\d+/,""));
				scRTpricing.init();
			}
			else {
				$(".item-info-price").html(jQuery("div.price",this).html());
				$("#pitSalePriceBx").html("$" + jQuery("div.price",this).html().match(/\d+\.\d+/,""));
				scRTpricing.init();
			}
				
			$(".addtocart input[name$='vwitem0']").val(jQuery("div.item-id",this).html().toLowerCase());
			$(".page-name").html(jQuery("div.name a",this).html());
			$(".code").html("Item #: " + jQuery("div.item-code",this).html());
			$(".item-caption div").html(jQuery("div.item-desc",this).html());
		});
	});
	$(".addtocartbutton").click(function() {
		$("#yfc_mini").scrollTo();									 
	});
});
