// JavaScript Document
$(document).ready(function () {

	$('.main_cat a').click(function(){
			var hc = $(this).parent().hasClass('bkg_pad_fix');
			var $this = $(this);
			$('.first_cat a').removeClass('on');
			if(hc){
			  $(this).parent().next().slideToggle( 1000, function(){$this.toggleClass('on');$(this).prev().toggleClass('bkg_pad_fix');} );
			} else {
			  $(this).toggleClass('on').parent().toggleClass('bkg_pad_fix').next().slideToggle( 1000 );
			}
			return false;
		});
		
		$('.sub_cat .sub a.on2').each(function(i){
		  $(this).parents('.sub_cat').prev().addClass('bkg_pad_fix');
		  $(this).parents('.sub_cat').slideDown( 1000 );
		});
		
		
	$('.industry').click(function () {
		changeTemplates($(this).attr('title'));
		$('.industry').removeClass('on');
		$('#featured').removeClass('on');
		$(this).addClass('on');
		
		if($(this).attr('id') == "custom" || $(this).attr('id') == "featured") {
			return true;
		} else {
			return false;
		}
	});
	$("#commander_login").click(function () {
		$('#login').submit();
		return false;
	});
});

function changeTemplates(tempText) {
	var tempTextPart = tempText.split('_');
	var query = "template="+tempTextPart[1];
	//alert(query);
	$.ajax({
		type: "POST",
		url: "ajaxphp/templateData.php",
		data: query,
		success: function(msg) {
			//alert(msg);
			$('#template_header').html(tempTextPart[0]+"<span class=\"template_small_desc\" id=\"title_header_message\" style=\"display: inline;\">Choose a design to get started.</span>");
			$('#template_desc_1').css('display', 'none');
			//$('#title_header_message').css('display', 'block');
			$('#template_sub_header').css('display', 'none');
			$('#template_start_desc').css('display', 'none');
			$('#left_col_content_container').html(msg);
			
			tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
			imgLoader = new Image();// preload image
			imgLoader.src = tb_pathToImage;
		}
	});
}
