/*
	Copyright DTDigital         :: www.dtdigital.com.au ::
	Unauthorised modification / use is a criminal offence, and
	will be prosecuted to the fullest extent permitted by law.
	All Rights Reserved
*/




// jQuery functions that run on "dom ready"

var _jQueryLoaded = (typeof(jQuery) == "function");

if (_jQueryLoaded)
{
	$(document).ready(function()
	{
		InitRolloverNavigation();
		InitRolloverInputs();
		
		// Makes links open in new window when they have rel=external
		$("a[@rel=external]").attr("target", "_blank");
		// Use below method if using thickbox, matches class rather than rel
		$("a.external-link").attr("target", "_blank"); 
	});
}

var _RolloverNavigationLoaded = false;
function InitRolloverNavigation()
{
	if (_jQueryLoaded && !_RolloverNavigationLoaded)
	{
		$(".rollover-navigation a").each(function()
		{
			$(this).find("img.navitem_prejs").each(function()
			{
				$(this).attr("class", "navitem_off");
			
				var newImage = $(this).clone();
		
				var newImageSrc = newImage.attr("src").replace("_0.gif", "_1.gif");
				newImage.attr("src", newImageSrc);
		
				newImage.attr("class", "navitem_hover");
		
				newImage.insertAfter(this);
			});
			
			$(this).focus(
				function()
				{
					$(this).toggleClass("hover");
				}
			).blur(
				function()
				{
					$(this).toggleClass("hover");
				}
			);
		});
		
		_RolloverNavigationLoaded = true;
	}
}

function InitRolloverInputs()
{
	if (_jQueryLoaded)
	{
		$(".rollover-input").each(function()
		{
			var imageSrc = $(this).attr("src");
			var imageName = imageSrc.substring(imageSrc.lastIndexOf("swap_") + 5, imageSrc.lastIndexOf("_"));
			
			for (var preloadLoop=0; preloadLoop < 2; preloadLoop++)
			{
				if (eval("typeof(b" + imageName + preloadLoop + ")") != "object")
				{
					eval("b" + imageName + preloadLoop + " = new Image()");
					eval("b" + imageName + preloadLoop + ".src = 'assets/swap_" + imageName + "_" + preloadLoop + ".gif'");
				}
			}
			
			$(this).mouseover(function()
			{
				$(this).attr("src", eval("b" + imageName + "1.src"));
			});
			
			$(this).mouseout(function()
			{
				$(this).attr("src", eval("b" + imageName + "0.src"));
			});

		});
	}
}

/*
Client-side access to querystring name=value pairs
Version 1.3
28 May 2008
http://adamv.com/dev/javascript/querystring
License (Simplified BSD): http://adamv.com/dev/javascript/qslicense.txt
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};
	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;
// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;
		this.params[name] = value;
	}
}
Querystring.prototype.get = function(key, default_) {
	var value = this.params[key];
	return (value != null) ? value : default_;
}
Querystring.prototype.contains = function(key) {
	var value = this.params[key];
	return (value != null);
}
/*
// To parse the current page's querystring:
var qs = new Querystring()
// To parse a given querystring - should not begin with a "?":
var qs2 = new Querystring("name1=value1&name2=value2&name3=value3")
// The following returns "value1"
var v1 = qs2.get("name1")
// The following returns "whoops"
var v1 = qs2.get("non-existent-parameter", "whoops")
// The following returns null
var v1 = qs2.get("non-existent-parameter")
// qs.contains(name) returns true if parameter "name" exists, else false.
// The following returns an alert box with "value1":
if (qs2.contains("name1")){ alert(qs2.get("name1"));}
*/

function OpenAddNewInThickBox(planID, taskType)
{
    tb_show("", "popup_add-task.aspx?openedfromjs=true&taskType=" + (taskType ? taskType : "") + "&planID=" + (planID ? planID : "") + "&TB_iframe=true&amp;width=747&amp;height=400", "");
}

function OpenEmailPlannerInThickBox(planID, memberID)
{
	tb_show("", "popup_email-plan.aspx?openedfromjs=true&planid=" + (planID ? planID : "") + "&memberid=" + (memberID ? memberID : "") + "&TB_iframe=true&amp;width=747&amp;height=328", "");
}


/* simple no-javascript alternative */
function JsAlt() {
	$(".alt_nojs").hide();
	$(".show_js").show();
}
$(function(){
	JsAlt();
});
