/* 	document on load cue
============================================================= */

$(document).ready(function() {			// always load these function when the DOM is ready
	p80jq_tabs();						// Easily create tabs
	p80jq_epandinglist(); 				// FAQ like exapding list on dl-tag with class dl.p80jq_expandinglist	
	p80jq_element_restore_value(); 		// Swap a classname on inputfields input|textarea.p80jq_element_restore_value	
	p80jq_zebra_table(); 				// alternating row colors for class tables.p80jq_zebra_table
	p80jq_src_hover();					// quick way of setting a swap image functionality on images with class img.p80jq_src_hover
});

/*	Text replacement
============================================================= */
var Cufon = Cufon || null;
if (Cufon){
Cufon.replace('h1, h2, h3, h4, h5, h6, .btn, .submit button');
Cufon.replace('.nav-main ul li a', 'h2', {
	hover: true
})};


/*	jQuery TOOLS / Tabs: http://flowplayer.org/tools/tabs.html
============================================================= */
function p80jq_tabs() {
	var tabs = $("ul.p80jqTabs").tabs("div.p80jqTabPanes > div.p80jqTab", { 
		current: "active",
		effect: 'fade',
		fadeOutSpeed: "slow",
		rotate: true

	}).slideshow({ 
		autoplay: true, 
		interval: 6000 
	});
}

/* 	jQuery FAQ like expanding list
============================================================= */

function p80jq_epandinglist(){
	// get all dl-tags with css class='p80jq_expandinglist'
	var faqList = $("dl.p80jq_expandinglist");
	
	// directly hide all the dd's on body.onload() (is also set using css)
	$("dd", faqList).hide();
	
	// set a click event on the dt's
	$("dt", faqList).click(onFaqListItemClick);
	
	// var openFaqItem = getQuerystring()["openitem"];
	var openFaqItem =  String (document.location).split ('#')[1] || '';
	if (openFaqItem != undefined)
	{
		// var faqItem = document.getElementById("openitem-" + openFaqItem);
		var faqItem = document.getElementById(openFaqItem);
		openFaqListItem(faqItem);
	}
}

function onFaqListItemClick(event)
{
	// close all
	var faqList = $("dl.p80jq_expandinglist");
	$("dt", faqList).removeClass("active");
	$("dd", faqList).hide();
	
	// open clicked
	openFaqListItem(this);
}

function openFaqListItem(elem)
{
	if (elem == undefined)
		return;

	var isOpen = (elem.className.match(/active/) == "active");
	
	if (!isOpen) {
		$(elem).addClass("active");		// add an 'active' css class
		$(elem).next("dd").toggle();	// and toggle inline css display none|block on the dd's
	}
}

/*	Restore defaultValue on form elements onblur
============================================================= */

function p80jq_element_restore_value() {
	$("input:text.p80jq_element_restore_value, textarea.p80jq_element_restore_value").each(function() {
		$(this).attr('p80_org_formvalue', $(this).val());
		$(this).addClass('p80_form_label');
	})
	.focus(function () {
		if($(this).val() != '' && $(this).val() == $(this).attr('p80_org_formvalue')) {
			$(this).val('');
			$(this).removeClass('p80_form_label');
		}					
	 })
	.blur(function() {
		if($(this).val() == '') {
			$(this).val($(this).attr('p80_org_formvalue'));
			$(this).addClass('p80_form_label');
		}
	});
}

/* 	jQuery alternating row colors (zebra_stripe_tables) 
	adds a 'odd' or 'even' classnames on all tables which have a classname of 'p80_zebra_table'
============================================================= */

function p80jq_zebra_table() {
	$("table.p80jq_zebra_table tbody tr").each(function(index) {	// to all tr-tags
		$(this).addClass(index % 2 == 0 ? "odd" : "even");			// add an 'odd' or 'even' classname
	});
}

/* 	jQuery rollovers on elements with a src-attribute
	on rollover 'demo.gif' becomes 'demo_hover.gif'
============================================================= */

function p80jq_src_hover() {
	$(".p80jq_src_hover").hover(function() { 									// classname to trigger
		var filename = $(this).attr("src").replace(/\.(\w+)$/, "_hover.$1");	// mouse-over: add the filename suffix
		$(this).attr("src", filename);
	}, function() {
		var filename = $(this).attr("src").replace(/_hover\.(\w+)$/, ".$1");	// mouse-out: restore, remove filename suffix
		$(this).attr("src", filename);
	});
}

/*	Thumbnail list on template index list
============================================================= */

function p80jq_toggle_thumbs(){
	$("img.index_thumb").each(function() {					// img-tags with 'index_thumb' classnames
		$(this).toggleClass("index_thumb_show"); 			// toggle the classname
	});
}

/*	Return a key/value array of the URL query-string
============================================================= */

function p80_get_query_string() {
	var querystring = new Array; 
	// parse current url into an array with the keys/values
	var q = String (document.location).split ('?')[1];
	// return if there is no url query string
	if (!q) return false;
	q = q.split ('&');	
	for (var i = 0 ; i < q.length; i++)	{
		// for each key/value, split them at the '='
		// and add them to the qerystring array
		var o = q[i].split('=');		
		// create the array and url decode the string
		querystring[o[0]] = unescape(o[1]);
	}	
	// return the querystring array
	return querystring;
}

/*	partner logo's
============================================================= */
$(document).ready(function(){	
	$(".partner-logos ul li:last-child").addClass("last");
});


