// JavaScript Document

// JavaScript Document
var $fp = jQuery.noConflict();

//do not change these values
var eventsOn = true;
var animationSpeed = 400;

//page is ready
$fp(document).ready(fp_READY);
//page is fully loaded
$fp(window).load(fp_LOAD);

function fp_READY(){
	fp_manip_dom();
	fp_bind_events();
}

function fp_manip_dom(){
	fp_load_images('#fp > ul > li:lt(3) > img');
	
	//uncomment this for development purposes only
	//it shows the visible footprint for the hotspot links
	//$fp('#fp > ul > li > a').css({opacity: .1, backgroundColor: "red"});
	
	var $slides = $fp('#fp > ul > li > a');
	$fp($slides).each(function() {
		if ($fp(this).attr('eventTag') != null && $fp(this).attr('eventTag').length > 0) {
			var myLink = $fp(this).attr('href');
			$fp(this).attr('href', '#');
			$fp(this).attr('clickAction', myLink);
			
			if ($fp(this).attr('target').length > 0) {
				$target = $fp(this).attr('target');
				$fp(this).removeAttr('target');
				$fp(this).attr('pageTarget', $target);
			}
			//var myTag = "WTExternalBridge('dcsMultiTrack', " + $corpPromoPanel(this).attr('eventTag') + ")";
			//$corpPromoPanel(this).attr('onClick', myTag);
			$fp(this).bind('click', fireEventLevelTagAndForwardToDestination);
		}
	});

}

function fireEventLevelTagAndForwardToDestination() {
	$tag = $fp(this).attr('eventTag');
	WTExternalBridge('dcsMultiTrack', $tag);
	if ($fp(this).attr('pageTarget') == "_blank") {
		window.open($fp(this).attr('clickAction'), "_blank");
	} else {
		window.location = $fp(this).attr('clickAction');
	}
}


function fp_load_images(imageSelector){
	$fp(imageSelector).each(function(index){
    	var title = $fp(this).attr('title');
		$fp(this).attr('src', title);
		$fp(this).removeAttr('title');
  	});
}

function fp_bind_events(){
	$fp('#fp_arrow_right').click(fp_arrow_right_CLICK);
}

function fp_arrow_right_CLICK(e){
	e.preventDefault();
	e.stopImmediatePropagation();
	
	if(eventsOn){
	
		var tag = jQuery.url.attr("path").replace(".aspx", "") + "/html_bottom_promo_move_right";
		WTExternalBridge('dcsMultiTrack', 'DCS.dcsuri,' + tag);
	
		eventsOn = false;
		fp_load_images('#fp > ul > li > img[title]:first');
		var mySlide = $fp('#fp > ul > li:first');
		mySlide.clone().appendTo('#fp > ul');
		mySlide.animate({width: 0}, {complete: fp_ANIMATE, duration: animationSpeed});
	}
	
	function fp_ANIMATE(){
		$fp(this).remove();
		eventsOn = true;
	}
}

function fp_LOAD(){
	fp_load_images('#fp > ul > li:eq(3) > img');
}
