/*
	Quetools Renderer Custom Script
	For Quetools Renderer
	Copyright 2010 Decomplexity
*/

/*
	Executed on DOM Ready	
*/
var domLoaded = function(){

	var redirectagent = navigator.userAgent.toLowerCase();
	var redirect_devices = ['vnd.wap.xhtml+xml', 'sony', 'symbian', 'nokia', 'samsung', 'mobile', 'windows ce', 'epoc', 'opera mini', 'nitro', 'j2me', 'midp-', 'cldc-', 'netfront', 'mot', 'up.browser', 'up.link', 'audiovox', 'blackberry', 'ericsson', 'panasonic', 'philips', 'sanyo', 'sharp', 'sie-', 'portalmmm', 'blazer', 'avantgo', 'danger', 'palm', 'series60', 'palmsource', 'pocketpc', 'smartphone', 'rover', 'ipaq', 'au-mic', 'alcatel', 'ericy', 'vodafone', 'wap1', 'wap2', 'teleca', 'playstation', 'lge', 'lg-', 'iphone', 'android', 'htc', 'dream', 'webos', 'bolt', 'nintendo'];
	for (var i in redirect_devices) {
	if (redirectagent.indexOf(redirect_devices[i]) != -1) {
	location.replace("http://m.ctcltd.com.au/");
	}
	}

	// Calendar Function
	highlightSelectedDay();
	
	/* Alternate Table Row Styling */
	$('.altRows tr:even').addClass('altColor');
	
	// Autosizes the mainmenu items to fill their containing UL element.
	// A width must be set on the top level <ul> element of the menu
	//elastoNav('#dMenu ul');
	
	$('.iText').each(clearFormValueFocus);
	$('.iSearch').each(clearFormValueFocus);

}


/*
	Executed on Window Load
*/
var contentLoaded = function(){

	//cleanup(); // Clear extra whitespace from content
	
	/*
		Set up Menus
	*/
	var arrow;
	var closeDelay = 400;
	
	$("ul.sf-menu").supersubs({ 
		minWidth:   12,
		maxWidth:   27,
		extraWidth: 1
	}).superfish({
		animation:  {opacity:'show',height:'show'},
		speed:		300,
		easing:		'swing',
		delay:		closeDelay,
		onBeforeShow: function(){ 
			
			arrow = ($(this).prev().after('<img class="arrow" src="'+serverroot+'/images/arrow.png" alt="" />'));
			$(this).prev().animate({opacity:'show'},300);
			$(this).addClass('open');
			
			
		},
		onHide: function(){ 

			if($(this).hasClass('open')){
				$(this).prev('.arrow').remove();
				$(this).removeClass('open');
				arrow = null;
			}

		}
	});	
	
	
	hideOverlay();
	
	/*
		Set up any UI Elements
	*/
	
	if($('.date')){
		
		$('.date').datepicker({
			dateFormat: "dd/mm/yy"
		});
		
		$('.date').removeClass('date');
		$('.date').removeAttr('date');
		
	}
	
	if($('.dRadioSet')) $('.dRadioSet').buttonset();
	if($('.dCheckSet')) $('.dCheckSet').buttonset();
	if($('.button, .termsbutton')) $('.button, .termsbutton').button();
	
	//$('#dScroller').nivoSlider();
	
	//$('.nivo-controlNav').css('width', $('.nivo-controlNav').width());
	
	// Autosizes the mainmenu items to fill their containing UL element
	// Run for a second time to check after images have loaded
	// A width must be set on the top level <ul> element of the menu
	elastoNav($('#dMenu ul'));
	
	$('.dFormError').delay(5000).fadeOut(2000);
	
	
	$('.aFormSubmitButton').click(function(event){
	
		event.preventDefault();
		$.scrollTo($('.error').filter(':first'));
	
	});

}

/*
	Tick Loading Animation
*/
var loadingTick = function(progress, canvas){
	
	// Draw loading animation here
	
}



