var $j = jQuery.noConflict();

$j(document).ready(function(){

	/* Fancybox Images */
	jQuery(function(){
		$j("a.single_image").fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'titlePosition'	: 'over',
			'speedIn'		: 600,
			'speedOut'		: 500,
			'centerOnScroll'	: true
		});
		$j("a.multi_images").fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'titlePosition'	: 'over',
			'speedIn'		: 600,
			'speedOut'		: 500,
			'centerOnScroll'	: true
		});
	});
	/* End Fancybox Images */

	/* Fancybox Iframe */
	jQuery(function(){
		$j("a.iframe").fancybox({
			'width'				: '75%',
			'height'			: '75%',
			'autoScale'     	: false,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'type'				: 'iframe',
			'titleShow'		    : false,
			'centerOnScroll'	: true
		});
	});
	/* End Fancybox Iframe */
	
	/* Fancybox Inline */
	jQuery(function(){
		$j("a.inline").fancybox({
			'width'				: '75%',
			'height'			: '75%',
			'autoScale'     	: false,
			'transitionIn'		: 'elastic',
			'transitionOut'		: 'elastic',
			'type'				: 'inline',
			'titleShow'		    : false,
			'centerOnScroll'	: true
		});
	});
	/* End Fancybox Inline */
	
	/* Draggable Fancybox */
	jQuery(function(){
		$j("#fancybox-wrap").easydrag();
	});
	/* End Draggable Fancybox */
	
	/* Zoom Icon */
	jQuery(function(){
		$j(".zoomImage a").append("<span></span>");
		$j(".zoomImage a").hover(function(){
			$j(this).children("img").stop(true, true).animate({opacity:0.7},300);
			$j(this).children("span").stop(true, true).fadeIn(300);
		},function(){
			$j(this).children("img").stop(true, true).animate({opacity:1},200);
			$j(this).children("span").stop(true, true).fadeOut(200);
		});
	});
	/* End Zoom Icon */

	/* Sticky Sidebar */
	jQuery(function(){
		$j("#sidebar .block-title").click(function(){
			$j(this).toggleClass("closed").next().slideToggle(300);
			return false;
		});
		$j("#narrow-by-list dt").click(function(){
			$j(this).toggleClass("closed").next().slideToggle(300);
			return false;
		});
		
		$j("#sidebar").append("<div class='trigger'><a href='#'>Sidebar</a></div>");
		
		if ($j.cookie("sidebar") == "off") {
			$j("#sidebar .trigger a").toggleClass("off");
			$j("#sidebar .content").css("margin-left", "-200px");
			
			$j("#sidebar .trigger a").toggle(function() {
				$j(this).toggleClass("off");
				$j("#sidebar .content").animate({marginLeft: "0"}, 300);
				$j.cookie("sidebar", "on", {path: '/'});
			},
			function(){
				$j(this).toggleClass("off");
				$j("#sidebar .content").animate({marginLeft: "-200px"}, 300);
				$j.cookie("sidebar", "off", {path: '/'});
				return false;
			});
		} else {
			$j("#sidebar .trigger a").toggle(function() {
				$j(this).toggleClass("off");
				$j("#sidebar .content").animate({marginLeft: "-200px"}, 300);
				$j.cookie("sidebar", "off", {path: '/'});
			},
			function(){
				$j(this).toggleClass("off");
				$j("#sidebar .content").animate({marginLeft: "0"}, 300);
				$j.cookie("sidebar", "on", {path: '/'});
				return false;
			});
		}
	});
	/* End Sticky Sidebar */
	
	/* Cart Quantity Buttons */
	jQuery(function(){
		$j("#shopping-cart-table tbody td.quantity").append('<div class="button dec">-</div><div class="button inc">+</div><div class="clear"></div>');
		$j(".button").click(function() {
			var button = $j(this);
			var oldValue = button.parent().find("input").val();

			if (button.text() == "+") {
				var newVal = parseFloat(oldValue) + 1;
			} else {
				if (oldValue >= 1) {
					var newVal = parseFloat(oldValue) - 1;
				}
			}
			button.parent().find("input").val(newVal);
		});
	});
	/* End Cart Quantity Buttons */

	/* Tooltip */
	jQuery(function(){

		xOffset = 10;
		yOffset = 30;
		
		$j("a.tooltipScreenshot").hover(function(e){
			$j("body").append("<img src='"+ this.rel +"' alt='Loading image preview...' id='tooltipScreenshot' />");
			$j("#tooltipScreenshot")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn("fast");
		},
		function(){
			$j("#tooltipScreenshot").remove();
		});
		$j("a.tooltipScreenshot").mousemove(function(e){
			$j("#tooltipScreenshot")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px");
		});
	
	});
	/* End Tooltip */

	/* Callouts Slider */
	jQuery(function(){
		$j("#callouts-slideshow").anythingSlider({
			easing: "swing",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 3000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 800,             // How long the slide transition takes
			hashTags: false,                 // Should links change the hashtag in the URL?
			buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
				pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
				startText: "Go",                // Start text
				stopText: "Stop"               // Stop text
		});
	});
	/* End Callouts Slider */
	
});
