/**
 * Common Javascript Functions
 *
 * Page that contains all common, non-AJAX javascript functions
 * 
 * @author gUncle Development [http://www.guncle.com]
 * @version 2.0 2/11/2010
 */

var SITE_TITLE = "Clearly Windows > ";

/**
 * Checks all checkboxes in row
 * @param {string} element = object sent
 */
function checkAll(element) {
	var row_id = 'row_' + element.id.substr(9);
	var checked = element.checked;
	$('#'+row_id+' input.checkbox').attr('checked',checked);
}


/**
 * Recolors alt rows in table
 * @param {string} element = id of table
 */
function colorAltRows(element) {
	if( document.getElementById(element) ) {
		var trs = document.getElementById(element).getElementsByTagName('tr');
		var num=1;
		for( var n=0; n<trs.length; n++ ) {
			var curclass = '';
			if( getClassName(trs[n]) ) {
				curclass += getClassName(trs[n]);
			}
			if( curclass.indexOf('formrow') < 0 ) {
				curclass = curclass.replace('alt','');
				if( num%2 ) {
					curclass += ' alt';
				}
				setClassName(trs[n],curclass);
				if( curclass.indexOf('hidden') < 0 ) {
					num++;
				}
			}
		}
	}
}


/**
 * Displays and hides loading box in header
 */
function loading(action) {
	var loading = document.getElementById('loading');
	if( action == 1 ) {
		var top = 40;
		if( window.pageYOffset ) {
			top += window.pageYOffset;
		}
		else if ( document.documentElement ) {
			top += document.documentElement.scrollTop;
		}
		else if ( document.body ) {
			top += document.body.scrollTop;
		}
		loading.style.top = top + 'px';
		loading.style.display = 'block';
	}
	else {
		loading.style.display = 'none';
	}
}


/**
 * Sets up actions of tab
 */
function tabSetup() {
	if( window.location.hash ) {
		var hash = window.location.hash.substr(1);
		$("#content_"+hash).fadeIn('fast');
		$("a[href$='"+hash+"']").addClass('active');
		document.title = SITE_TITLE + $("#content_"+hash+" > h2").html();
	}
	else {
		$("#content_main").fadeIn('fast');
	}
	$("#submenu a").click(function(){
		var hash = $(this).attr('href').substr(1);
		$("div[id^='content_']").fadeOut('fast');
		$("#content_"+hash).delay(200).fadeIn('slow');
		$("#submenu a").removeClass('active');
		$(this).addClass('active');
		document.title = SITE_TITLE + $("#content_"+hash+" > h2").html();
	});
	$("#submenu .clickable").click(function(){
		$("div[id^='content_']").fadeOut('fast');
		$("#content_"+$(this).attr('rel')).delay(200).fadeIn('slow');
		$("#submenu a").removeClass('active');
		window.location.hash = '#'+$(this).attr('rel');
		document.title = SITE_TITLE + $("#content_"+$(this).attr('rel')+" > h2").html();
	});
}


function interiorSlideShow() {
	$('#heroInteriorImgs').cycle({
		timeout:       5000,
		speed:         1500,
		pause:         1
	});
}


function homeSlideShow() {
	$('#heroHomeImgs').cycle({
		timeout:       6000,
		speed:         1500,
		pause:         1
	});
}
