// Code by Martìn Acuña Lledó <martin@sumagency.com>
// 2008-04-04
// modified by Mel Padden for Fractis 2008-06-11

$(document).ready(function() {
	// *********************** Strips *************************** 
	var flagStrip = false;
	var stripOpt = '#strip_content_option_';

	// Strip buttons
	$('li.option_strip').click(
		function() {
			var idNumber = ('#' + $(this)[0].id).replace('#option_', '');
			showStrip(idNumber);
		}
	);

	$('.next_strip').click(function() { // Next link click event
		var parent = $(this)[0].parentNode
		var idNumber = ('#' + parent.id).replace(stripOpt, '');
		var nextStrip = $(stripOpt + idNumber + ' + div.strip'); // Get the next node
		if (nextStrip.size() > 0) {
			showStrip(('#' + nextStrip[0].id).replace(stripOpt, ''));
		} else {
			showStrip(1); // show first option if this is past the end
		}
	});


	showStrip = function(id) {
		var objVisibles = $('#strip_content_options > div.strip:visible');
		var newVisible = $(stripOpt + id)
		if (objVisibles.size() > 0) {
			if ((objVisibles[0].id != newVisible[0].id) && (!flagStrip)) {
				flagStrip = true;
				$("#strip_tabs > li > a.on").removeClass("on").addClass("off");
				$("#option_" + id + " > a").removeClass("off").addClass("on");
				objVisibles.fadeOut('fast', function() {
					newVisible.fadeIn('fast', function() {
						flagStrip = false;
					});
				});
			}
		}
		return false;
	}

	// Do pop up on the download links
	$('a.evaluate_link').click(
		function(event) {
			event.preventDefault();

			$.cookie("source", $(this).attr("source") || "<unspecified>", { path: '/'});
			var url = "request_a_quote.html?placeValuesBeforeTB_=savedValues&TB_iframe=true&height=570&width=410";

			tb_show("Request a Quick Quote", url, false);
			this.blur();
		}
	);

	// Do pop up on the generic video links
	$('a.video_link').click(
		function(event) {
			event.preventDefault();
			var url = $('#' + event.target.id).href;
			
			tb_show("Iceberg Video", url, true);
			this.blur();
		}
	);

	// Do pop up on the tour video image links
	//$('div.video_img_wrapper').click(
		//function(event) {
		//	var url = "/geticebergtourvideo.php?TB_iframe=true&amp;height=486&amp;width=550&amp;modal=false";
		//	tb_show("Iceberg Tour Video", url, true);
		//}
	//);
	
	// set up the referrer cookie
	if (!$.cookie("referrer")) $.cookie("referrer", document.referrer || "<none>", { path: '/'});
	
	//set upt he active tab
	$("#nav li#" + document.body.id).addClass("active");

	// ************************* Download Box ***************************
	var toHideTimer = null;
	var flagBox = false;
	var dwMsgMarginTop = '15px';

	$('#option_img').mouseover(function() {
		if (toHideTimer) clearTimeout(toHideTimer);
		if (!flagBox) {
			flagBox = true;
			$('#option_img').fadeTo('fast', 0.20, function() {
				$(this).removeClass("off").addClass("on");
				$(this).fadeTo('fast', 1, function() {
					$('#download_message').css('visibility', 'visible');
					$('#download_message').animate({
						marginTop: '-=' + dwMsgMarginTop,
						opacity: 1.0
					}, 250, 'swing');

				});
			});

		}
	});
	$('#option_img').mouseout(function() {
		if (flagBox) {
			toHideTimer = setTimeout(function() {
				$('#download_message').animate({
					marginTop: '+=+' + dwMsgMarginTop,
					opacity: 0.0
				}, 250, 'swing', function() {
					$('#download_message').css('visibility', 'hidden');
					$('#option_img').fadeTo('fast', 0.20, function() {
						$(this).removeClass("on").addClass("off");
						$(this).fadeTo('normal', 1, function() {
							flagBox = false;
						});
					});
				});
			}, 500);
		}
	});
});

