/**
 * Carousel Extension
 *
 * Carousel Extension Code for SquidCMS
 *
 * jQuery version 1.2.6, jCarousel version 0.2.3
 *
 * @author		Vincent Lu <vincent@enke.com.au>
 * @copyright	2006-2009 Enke Design
 * @since		2008-11-20 16:22
 * @version		1.2
 */


function initiate_carousel(number, target) {
	if (!number) {
		number = 3;
	}

	if (!target) {
		target = '.carousel';
	}

    jQuery(target).jcarousel({
        size: image.length,
        itemLoadCallback: {onBeforeAnimation: loadimage},
		scroll: number
    });

	/*var width = jQuery(target).parent().width() + gallery.gallery_arrow_width/2;
	var container_width = jQuery("#contentpage").width();

	var marginleft = (Math.floor((container_width-width)/2));
	jQuery("#carousel_wrap").css({
		position: "relative",
		left: marginleft+"px",
		width: width+"px"
	});*/
}

function loadimage (carousel, state) {
    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) {
            continue;
        }

        if (i > image.length) {
            break;
        }

        var item = jQuery(getHTML(image[i-1], gallery.gallery_link_type)).get(0);

		if (image[i-1].image_url == "feature") {
			tb_init(item);
		}
        carousel.add(i, item);
    }
};

function getHTML (item, link_type) {

	if (item.image_url != "" && item.image_url != 0 && item.image_url != "feature") {
		//Linking externally
		var anchorHTML = "<a href=\"" + item.image_url + "\" target=\"_blank\">";
	}else{
		//Internal link
		if (item.image_url == "feature") {
			//Feature page link
			var anchorHTML = "<a href=\"" + connector + "?geturls=featurepage.php?id=" + item.image_id_page + "&width=800&height=500\" class=\"thickbox\">";
		}else{
			//Direct link
			var anchorHTML = "<a href=\"" + root + "/?id=" + item.image_id_page + "\">";
		}
	}
	//Enke - Dan: [30-09-09] change to gallery so we can easily style gal different to core look. Needs to be interagrated as its own feature into Zaum

	//if (amac_custom == "1") {
	var result =
		anchorHTML +
		"<img class=\"image_item\" onmouseover=\"on_effect(this)\" onmouseout=\"off_effect(this)\" width=\"" + gallery.gallery_width + "\" height=\"" + gallery.gallery_height + "\" src=\"" + item.image_base + "\" border=\"0\" alt=\"" + item.image_title + "\" />" +
		"<div class=\"img_txt\"><span>" + item.image_title + "</span><br />"+ item.image_description +"</div></a>";
	/*} else if(amac_custom == "2") {
	var result =
		anchorHTML +
		"<img class=\"image_item\" onmouseover=\"on_effect(this, '" + item.image_title + "');\" onmouseout=\"off_effect(this)\" width=\"" + gallery.gallery_width + "\" height=\"" + gallery.gallery_height + "\" src=\"" + item.image_base + "\" border=\"0\" alt=\"" + item.image_title + "\" />" +
		"</a>";
	}*/
	return result;
};

function on_effect(target, image_title, image_description) {
	//jQuery(target).after("<div id='image_text'>"+image_title+"<div><br />"+image_description+"</div></div>");
	//if (amac_custom = 2) {
		//jQuery(target).after("<div id='image_text'>"+image_title+"</div>");
	//}
	effect_call(1, target);
}

function off_effect(target) {
	jQuery("#image_text").remove();
	effect_call(1, target);
}

function effect_call(id, target) {
	switch (id) {
		case 1:
			effect_opacity(target);
			break;
		case 2:
			break;
		default:
			break;
	}
}

function effect_opacity(target) {
	var current_opacity = jQuery(target).css("opacity");

	if (current_opacity == "0.8") {
		jQuery(target).css("opacity", "1");
	}else{
		jQuery(target).css("opacity", "0.8");
	}
}

