/*************************************
	DOCUMENT NAME: SOURCE.JS
	CLIENT: VITALOGY SKINCARE
	AUTHOR: MICHAEL LESHER (www.thehivemedia.com)
	DATE: 07/07/2010
*************************************/

$(document).ready(function() {
	// EVENT LISTENERS
	$('#mast h2').click(function() { sendHome(this); });	
	$('#navigation a').mouseover(function() { setRolloverState(this,0); });
	$('#navigation a').mouseout(function() { setRolloverState(this,1); });	

	// PRIMARY FUNCTIONS	
	setNavigationStatus();
	loadContainerHeight();
	loadContentHeight();
});

function loadContainerHeight() { 
	var container = new Object();
		container.height = $('#container').height();
		container.window = $(document).height();
		container.buffer = 0;		
	if(container.height < container.window) { 
		container.buffer = parseInt(container.window - container.height);
		$('#container').css('paddingBottom',container.buffer);		
	}
}

function loadContentHeight() { 
	var content = new Object();
		content.height = $('#content .main').height();
		content.sidebar = $('#content .sidebar').height();
		content.buffer = 0;		
	if(content.height < content.sidebar) { 
		content.buffer = parseInt((content.sidebar - content.height) + 80);
		$('#content .main').css('paddingBottom',content.buffer);
	}
}

function sendHome(obj) { 
	var home = new Object();
		home.path = $(obj).attr('param');
	location.href = home.path;
}

function setNavigationStatus() { 
	var ison = new Object();
		ison.path = $('#content').attr('param');
		ison.source = $('#navigation').attr('param');		
	if(ison.source != 'index') { 
		$('#navigation a').each(function() { 
			ison.test = $(this).attr('class').split('link-');		
			ison.link = ison.test[1];
			if(ison.source == ison.link) { 
				ison.css = 'url("' + ison.path + 'core/img/global/navigation/ICN-' + ison.link + '-on.jpg") no-repeat top left';				
				$(this).attr('param','ison');
				$(this).css('background',ison.css);
			}
		});	
	}
}

function setRolloverState(obj,eve) { 
	var rollthis = new Object();
		rollthis.obj = obj;
		rollthis.eve = eve;
		rollthis.path = $('#content').attr('param');
		rollthis.ison = $(obj).attr('param');
		rollthis.source = $(obj).attr('class').split('link-');		
		if(rollthis.ison != 'ison') {
			if(rollthis.eve == 0 && rollthis.source[1] != 'home') { 
				rollthis.background = rollthis.source[1] + '-on.jpg';
			} else { 
				rollthis.background = rollthis.source[1] + '.jpg';		
			}
			rollthis.css = 'url("' + rollthis.path + 'core/img/global/navigation/ICN-' + rollthis.background + '") no-repeat top left';
			$(obj).css('background',rollthis.css);		
		}	
}

