//<![CDATA[
var path = STORE_URL;
var path_frontpage = SKIN_URL + 'images/frontpage/';
var thisCarousel;
var thisTimer;

var rotateImages = [
	{url: path_frontpage + 'rotate_img_001.jpg', ref: path + "facts/organic-lifestyle"},
	{url: path_frontpage + 'rotate_img_002.jpg', ref: path + "best-in-test"},
	{url: path_frontpage + 'rotate_img_003.jpg', ref: path + "clay"},
	{url: path_frontpage + 'rotate_img_004.jpg', ref: path + "abonnement-pakke"}
];
	
var mycarousel_itemList = [
    {url: "img_carousel_1.jpg", title: "Ansigt", 	ref: path + "face-care"},
    {url: "img_carousel_2.jpg", title: "Baby",		ref: path + "baby-care"},
    {url: "img_carousel_3.jpg", title: "Parfume", 	ref: path + "parfume"},
    {url: "img_carousel_4.jpg", title: "Hygiejne", 	ref: path + "hygiene"},
    {url: "img_carousel_5.jpg", title: "Krop", 		ref: path + "body-hand-care"},
    {url: "img_carousel_6.jpg", title: "Ler", 		ref: path + "clay"},
    {url: "img_carousel_7.jpg", title: "Uren hud", 	ref: path + "teenage-acne"}
];

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));

	thisCarousel = carousel;
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

function mycarousel_getItemHTML(item)
{
    return "<a href='" + item.ref + "'><img src='" + path_frontpage + item.url + "' alt='" + item.title + "' /></a>";
};

function moveToNextImage() {
	thisCarousel.next();	
	setImages();
}

function setTimer() {
	thisTimer = setInterval( moveToNextImage, 10000 );	
	//	alert(thisTimer);
}

function setImages() {		
	jQuery("#mycarousel img").unbind("mouseover").unbind("mouseout");
	
	jQuery("#mycarousel img").bind("mouseover", function() {
		jQuery(this).animate({
			"opacity":"0.8", 
			//"marginTop": "-20px",
			"position": "relative"
			}, 1000);
		
		//clearInterval( thisTimer );
		return false;
	});
	jQuery("#mycarousel img").bind("mouseout", function() {
		jQuery(this).animate({"opacity":"1.0", "marginTop":"0px"}, 1000);
		//setTimer();
		return false;
	});
}

jQuery(document).ready(function() {
    
	if(jQuery("#mycarousel")) {
		jQuery("#mycarousel").jcarousel({
			scroll: 1,
			animation: "slow",
			wrap: "circular",
			itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
			itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},
			// This tells jCarousel NOT to autobuild prev/next buttons
			buttonNextHTML: null,
			buttonPrevHTML: null
		});
		
		setTimer();
		setImages();
		
		// 
		jQuery(".col-main").css("padding","0");
	}
	
	if(jQuery("#rotate-img")) {
		var iRotateImage = 0;
		jQuery("#rotate-img").attr("src",rotateImages[iRotateImage].url).parent().attr("href",rotateImages[iRotateImage].ref);
		// Rotational images
		setInterval( function() {		
			if (iRotateImage == (rotateImages.length - 1)) iRotateImage = 0; else iRotateImage++;
			jQuery("#rotate-img")
				.fadeOut("slow", function() {
					jQuery("#rotate-img").attr("src",rotateImages[iRotateImage].url).fadeIn("slow").parent().attr("href",rotateImages[iRotateImage].ref);
				} );
		}, 8000);
	}
});
//]]>