/*******************************************************************************

	CSS on Sails Framework
	Title: LINEAR technology
	Author: XHTMLized (http://www.xhtmlized.com/)
	Date: March 2011
	Modified By: Scott June 2011 
	(moved window load script to evenUp function so it could be used elsewhere & added reset to height:auto)

*******************************************************************************/

function bodyResize(){
	var windowHeight = $(window).height();
	var bodyHeight = $('body').outerHeight();
	//console.log(windowHeight, bodyHeight);
	if ( windowHeight > bodyHeight ) {
		$('body').css({'height': windowHeight-37+'px'});
	}
	if ( windowHeight < bodyHeight ) {
		$('body').css({'height': 'auto'});
	}
};

function evenUp(){
	$('.sub #sidebar .box:last-child').css({'height': 'auto'});
    $('.sub #content').css({'height': 'auto'});
	var contentHeight = $('.sub #content').outerHeight();
	var sidebarHeight = $('.sub #sidebar').outerHeight();
	var sidebarBoxHeight = $('.sub #sidebar .box:last-child').outerHeight();
	var sidebarDifference = sidebarHeight - sidebarBoxHeight;
	if ( contentHeight > sidebarHeight ) {
		$('.sub #sidebar .box:last-child').css({'height': contentHeight - sidebarDifference + 7 + 'px'});
	}
	if ( contentHeight < sidebarHeight ) {
		$('.sub #content').css({'height': sidebarHeight - 40 + 'px'});
	}
};

$(document).ready(function() {

	//
	$('#header form fieldset input[type="text"]').each(function() {
		var defaultValue = this.value;
		$(this).focus(function() {
			if(this.value == defaultValue) {
				this.value = '';
			}
		});
		$(this).blur(function() {
			if(this.value == '') {
				this.value = defaultValue;
			}
		});
	});
	
	//$('#header form fieldset input[type="text"]:first').focus();
	
	//
	if($('.scroll-pane').length > 0){
		$('.scroll-pane').jScrollPane({showArrows: true});
	}
	//
    if($('.home select').length > 0){
		$('.home select').selectmenu();
	}

	if (($.browser.msie) && ($.browser.version == "8.0")){

		// CSS3PIE
		var CSS3PIE_selectors = [
			'.users-menu',
			'.home #content .nav li ul',
			'.box h2',
			'.box',
			'#navigation',
			'#navigation li a',
			'#content',
			'#header'
		];
		$( CSS3PIE_selectors.join(',') ).each(function() {
			PIE.attach(this);
		});
	}

	//
	if (($.browser.msie) && ($.browser.version == "8.0")){
	}

	//
	if (($.browser.msie) && ($.browser.version == "7.0")){
	}

});

if (($.browser.mozilla) && (parseInt($.browser.version) <= 3)){
	var link = $("<link>");
	link.attr({type: 'text/css',rel: 'stylesheet',href: '/_ui/css/ie_eng.css'});
	$("head").append(link); 
}

$(window).load(function() {

	//
	evenUp();
	bodyResize();

});

$(window).resize(function() {

	bodyResize();

});

