﻿// -------------------
// Caneline Imagecycle
// -------------------
function StartImageCycle(strImageSelectorID, strPagerSelectorID) {
	jQuery(strPagerSelectorID).empty();
	jQuery(strImageSelectorID).cycle({
		fx: 'fade',
		speed: 5000,
		timeout: 15000,
		pager: strPagerSelectorID,
		pagerAnchorBuilder: function(idx, slide) {
			return '<li><a href="' + slide.src + '"><img src="gfx/blank.gif" /></a></li>';
		}
	});
}

// ------------------
// Caneline Global JS
// ------------------
var intCloseMainMenuTimer;
function CloseDelayed() {
	intCloseMainMenuTimer = window.setTimeout(function() { CloseMenu() }, 1500);
}
function ResetCloseTimer() {
	window.clearTimeout(intCloseMainMenuTimer);
}
function CloseMenu() {
	jQuery("li.Sub1").css({ 'white-space': 'nowrap' });
	jQuery("li.Sub2").css({ 'white-space': 'nowrap' });
	jQuery("#Navigation").animate({ width: "0px" }, 500, "swing", function() {
		jQuery("#Navigation>div").hide();
	});
	jQuery("#Navigation>div").animate({ width: "0px" }, 500, "swing", function() {
		jQuery("#Navigation").hide();
		jQuery("#NavigationClosed").show();
		jQuery("li.Sub1").css({ 'white-space': 'normal' });
		jQuery("li.Sub2").css({ 'white-space': 'normal' });
	});
}
function OpenMenu() {
	jQuery("li.Sub1").css({ 'white-space': 'nowrap' });
	jQuery("li.Sub2").css({ 'white-space': 'nowrap' });
	jQuery("#Navigation").show();
	jQuery("#NavigationClosed").hide();
	jQuery("#Navigation>div").animate({ width: "110px" });
	jQuery("#Navigation").animate({ width: "130px" }, 500, "swing", function() {
		jQuery("#Navigation>div").show();
		jQuery("li.Sub1").css({ 'white-space': 'normal' });
		jQuery("li.Sub2").css({ 'white-space': 'normal' });
	});
}


// -------------------------------------
// Generic caneline menu open behaviour 
// -------------------------------------
function CloseDownBox(strBoxID, objButton, intAnimationSpeed) {
	if (!intAnimationSpeed) { intAnimationSpeed = 500; }
	if (jQuery("#" + strBoxID).css("display") == "block") {
		jQuery("#" + strBoxID).animate({
			height: "0px",
			paddingTop: "0px",
			paddingBottom: "0px"
		}, intAnimationSpeed, "swing", function() {
		jQuery("#" + strBoxID).hide();
			jQuery(objButton).unbind("click");
			jQuery(objButton).bind("click", function() { OpenUpBox(strBoxID, this, intAnimationSpeed); });
		});
	}
}

function OpenUpBox(strBoxID, objButton, intAnimationSpeed) {
	if (!intAnimationSpeed) { intAnimationSpeed = 500; }
	if (jQuery("#" + strBoxID).css("display") == "none") {
		var intAutoHeight;
		jQuery("#" + strBoxID).css("visibility", "hidden");
		jQuery("#" + strBoxID).css("padding-bottom", "5px");
		jQuery("#" + strBoxID).css("padding-top", "15px");
		jQuery("#" + strBoxID).css("height", "auto");
		intAutoHeight = parseInt(jQuery("#" + strBoxID).height());
		jQuery("#" + strBoxID).css("height", "0px");
		jQuery("#" + strBoxID).css("padding-bottom", "0px");
		jQuery("#" + strBoxID).css("padding-top", "0px");
		jQuery("#" + strBoxID).css("visibility", "visible");
		jQuery("#" + strBoxID).hide();
		jQuery("#" + strBoxID).animate({
			height: intAutoHeight + "px",
			paddingTop: "15px",
			paddingBottom: "5px"
		}, intAnimationSpeed, "swing", function() {
			jQuery(this).css("overflow", "hidden");
			jQuery(objButton).unbind("click");
			jQuery(objButton).bind("click", function() { CloseDownBox(strBoxID, this, intAnimationSpeed); });
		});
		jQuery("#" + strBoxID).css("overflow", "hidden");
	}
}

function ResizeBox(strBoxID, objButton, intAnimationSpeed) {
	if (!intAnimationSpeed) { intAnimationSpeed = 200; }
	if (jQuery("#" + strBoxID).css("display") == "block") {
		var intAutoHeight;
		var intCurrentHeight = parseInt(jQuery("#" + strBoxID).height());
		//jQuery("#" + strBoxID).css("visibility", "hidden");
		jQuery("#" + strBoxID).css("padding-bottom", "5px");
		jQuery("#" + strBoxID).css("padding-top", "15px");
		jQuery("#" + strBoxID).css("height", "auto");
		intAutoHeight = parseInt(jQuery("#" + strBoxID).height());
		jQuery("#" + strBoxID).css("height", intCurrentHeight + "px");
		//jQuery("#" + strBoxID).css("visibility", "visible");
		//jQuery("#" + strBoxID).hide();
		jQuery("#" + strBoxID).animate({
			height: intAutoHeight + "px"
		}, intAnimationSpeed, "swing", function() {});
	}
}

function BindClickEventToMenu(strMenuElementID, strToggleElementID, strTimerVariableName, intAnimationSpeed) {
	if (!intAnimationSpeed) { intAnimationSpeed = 500; }
	// Unbind all events for the object before we go any further 
	jQuery("#" + strToggleElementID).unbind();
	jQuery("#" + strMenuElementID).unbind();
	
	// Should a close function be binded to the element or a open function 
	if (jQuery("#" + strMenuElementID).css("display") == "none") {
		jQuery("#" + strToggleElementID).bind("click", function() {
			eval('window.clearTimeout(' + strTimerVariableName + ');');
			OpenUpBox(strMenuElementID, jQuery("#" + strToggleElementID), intAnimationSpeed);
		});
	} else {
		jQuery("#" + strToggleElementID).bind("click", function() {
			eval('window.clearTimeout(' + strTimerVariableName + ');');
			CloseDownBox(strMenuElementID, jQuery("#" + strToggleElementID), intAnimationSpeed)
		});
	}

	// Add onmouse over events to the elements 
	jQuery("#" + strToggleElementID).bind("mouseover", function() {
		eval('window.clearTimeout(' + strTimerVariableName + ');');
	});
	jQuery("#" + strMenuElementID).bind("mouseover", function() {
		eval('window.clearTimeout(' + strTimerVariableName + ');');
	});

	// Add onmouseout events to the elements
	jQuery("#" + strToggleElementID).bind("mouseout", function() {
		eval('window.clearTimeout(' + strTimerVariableName + ');');
		eval(strTimerVariableName + ' = window.setTimeout(function() { CloseDownBox("' + strMenuElementID + '", jQuery("#' + strToggleElementID + '"), ' + String(intAnimationSpeed) + ') }, 1500);');
	});
	jQuery("#" + strMenuElementID).bind("mouseout", function() {
		eval('window.clearTimeout(' + strTimerVariableName + ');');
		eval(strTimerVariableName + ' = window.setTimeout(function() { CloseDownBox("' + strMenuElementID + '", jQuery("#' + strToggleElementID + '"), ' + String(intAnimationSpeed) + ') }, 1500);');
	});
}
