/**
 * Author => Company       : Prodo Ltd
 *        => Website       : http://www.prodo.com
 * Code   => Last Modified : 08 December 2009
 */

$(function() {
	
	// 
	$('a[rel=external]').click(function(e) {
		open(this.href);
		e.preventDefault(); 
	}).attr('title', 'Opens in a new window');
	
	// 
	$('a[href$=.pdf]').click(function(e) {
		open(this.href);
		e.preventDefault();
	}).addClass('pdf');
	
	// Default Field Values
	$('.search input[type=text]').DefaultValue('Search our site...');
	
	// 
	if($('#header .banner .image')) {
		$('#header .banner .image').append('<img alt="" height="215" src="/App_Themes/thedebtadvisor/img/animation/1.jpg" width="480" />');
		$('#header .banner .image').append('<img alt="" height="215" src="/App_Themes/thedebtadvisor/img/animation/2.jpg" width="480" />');
		$('#header .banner .image').append('<img alt="" height="215" src="/App_Themes/thedebtadvisor/img/animation/3.jpg" width="480" />');
		$('#header .banner .image').innerfade({
			containerheight : '215px',
			speed           : 'slow',
			timeout         : 4000,
			type            : 'random_start'
		});
	}
	
	// 
	if($.getUrlVar('cmspagemode') == 'edit') {
		// when editing a page don't hide unused sections incase we want to drop something in them
	}
	else {
		if($('body.home').length) {
			// don't go hiding stuff on the homepage
		} else {
			if(($.trim($('#navigation').html()) == '') && ($.trim($('#sidebar').html()) == '')) {
				$('body').removeAttr('class').addClass('single-column');
			}
			else if(($.trim($('#navigation').html()) == '') && ($.trim($('#sidebar').html()) != '')) {
				$('body').removeAttr('class').addClass('double-column');
			}
		}
	}
	
});

// Get URL Parameters
$.extend({
	getUrlVars : function() {
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++) {
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	},
	getUrlVar : function(name) {
		return $.getUrlVars()[name];
	}
});