
$().ready(function(){
	fixLiWidths('blogPosts');
	fixLiWidths('products');
	$("#blogPosts .heading li, #products .heading li, #products .item a, #potd .item, #blogPosts .posts a").hover(
		function(){
			$(this).addClass('sfhover');
		},
		function(){
			$(this).removeClass('sfhover');
		}
	);
	signUpCookie = Get_Cookie( 'signUpClosed' );
	if (signUpCookie == null) {
		$('#signUp').show();
	}
});

function loadBlogPosts(wSortBy){
	var query = "sortby=" + wSortBy;
	
	$("#blogPosts .heading .loading").show();
	$.get("/common_gl/inc_home_blog.php", query, function(data){
		$("#blogPosts .posts").html(data);
		
		$("#blogPosts .heading .loading").hide();
		
		$("#blogPosts .heading h2").html($("#blogPosts .heading li."+wSortBy+" a").html());
		
		$("#blogPosts .heading li").removeClass('sel');
		$("#blogPosts .heading li."+wSortBy).addClass('sel');
		
		fixLiWidths('blogPosts');
	});
}

function loadProducts(wSortBy){
	var query = "sortby=" + wSortBy;
	
	$("#products .heading .loading").show();
	$.get("/common_gl/inc_home_products.php", query, function(data){
		$("#products .items").html(data);
		
		$("#products .heading .loading").hide();
		
		$("#products .heading h2").html($("#products .heading li."+wSortBy+" a").html());
		
		$("#products .heading li").removeClass('sel');
		$("#products .heading li."+wSortBy).addClass('sel');
		
		fixLiWidths('products');
	});
}

function fixLiWidths(wId){
	var maxWidth = 0;
	$("#"+wId+" .heading li, #"+wId+" .heading h2").css({ 'width':'auto' });
	maxWidth = Math.max(maxWidth, $("#"+wId+" .heading ul:first").innerWidth());
	$("#"+wId+" .heading li ul li").each(
		function(){
			maxWidth = Math.max(maxWidth, $(this).innerWidth());
		}
	);
	$("#"+wId+" .heading li ul li").css({
		'width':maxWidth
	});
	$("#"+wId+" .heading h2").css({
		'width':maxWidth-38
	});
}




function closeSignUp(){
	Set_Cookie( 'signUpClosed', '1', 14, '/' )
	$('#signUp').hide();
}