/*------------------------------------------------------------------------------
 * home.js
 *
 * Javascript for the homepage of lovepork.co.uk
 *----------------------------------------------------------------------------*/
$(document).ready(function() {

	$("#home-video").prepend('<div id="scroll-left"></div>');
	$("#home-video").prepend('<div id="scroll-right"></div>');

	$('.slideshow').cycle({
		fx: 'fade',
		speed: 2500,
		timeout: 2500,
		next: '#scroll-right',
		prev: '#scroll-left',
		cleartype: false
	});

	$(".reveal-video").click(function () {
		var thePath = $(this).attr("href");
		$('.slideshow').cycle('pause');
		$(this).fadeOut(1000, function () {
			$(this).parent().prepend('<div id="mediaspace">This div will be replaced</div>');
			loadVideo(thePath);
		  });
		return false;
	});

	$("#scroll-right, #scroll-left").click(function() {
		$("#mediaspace").remove();
		$(".reveal-video").css("display", "block");
		 $('.slideshow').cycle('resume');
	});

	$("#home-pork-more").hover(
	  function () {
		$("p", this).addClass("onscreen");
		$("p", this).stop().animate({"height": "45px"}, "normal");
	  },
	  function () {
		$("p", this).stop().animate({"height": "1px"}, "normal", "", function() {
			$(this).removeClass("onscreen");
		});
	  }
	);

	/* image rotate code */
    $("img.rotate").each(function () {
        var img = $(this);
        var imageUrls = img.attr("data-rotate").split(",");
        var position = 0;
        setInterval(function() {
            img.animate({
                opacity: 0.01
            }, 1250, function() {
                position++;
                if (position >= imageUrls.length) {
                    position = 0;
                }
                img.attr("src", imageUrls[position]).animate({
                    opacity: 1
                }, 1250);
            });
        }, 10000);
    });
    
});

/*------------------------------------------------------------------------------
 *
 * AHD01 1i10079-001: Sausage week 2010
 *
 * Sausage week 2010 homepage updates
 *
 * Date: 05/10/2010
 * Author: Chris Sheppard
 *
 *----------------------------------------------------------------------------*/
sIFR.replace({src: '/assets/swf/ElGrande.swf'}, {
	wmode: 'transparent',
	selector: '#home-sausage-week-2010 h1',
	offsetTop: "-10",
	tuneHeight: "-20",
	css: '.sIFR-root { color: #ffffff; }'
});
sIFR.replace({src: '/assets/swf/ElGrande.swf'}, {
	wmode: 'transparent',
	selector: '#home-sausage-week-2010 h2',
	offsetTop: "-15",
	tuneHeight: "-25",
	css: '.sIFR-root { color: #b17bd1; }'
});
