var GLOBAL_TIME = 5;

function counting() {
	
}

function initMenu() {
	
	$('ul.thecategory ul').hide();
	
	$('ul.thecategory li a').click(function() {
		var checkElement = $(this).next();
		
		$("#content").empty().append("<div style='text-align:center;padding:10%;'><img src='http://www.dikani.com/images/ajax-loader.gif' alt='' /></div>");
		
		// getting the ajax
		var href = $(this).attr("href");
		var newurl = href.replace("browse/","ajax/");
		newurl = newurl.replace("category/","thecategory/");
		
		// if in the shops
		if(href.indexOf("www") == -1) return true;
		
		var thelocation = newurl.replace("http://www.dikani.com/index.php/","");
		var currentlocation = document.location.href;
		var datalocation = currentlocation.split("#");
		
		var newlocation = datalocation[0] + "#" + thelocation;
		document.location = newlocation;
		document.location.replace(newlocation);
		
		// activestate
		$(".activestate").each(function() {
			$(this).removeClass("activestate");
		});
		$(this).addClass("activestate");
		
		
		if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			
			if($(this).parents(".childs").length == 0) {
				$('ul.thecategory ul:visible').slideUp('slow',function() {
					setTimeout(
						function() { 
							$.ajax({
								url: newurl,
								data: "GET",
								async: false,
								success: function(contents) {
									$("#content").empty().append("<br />"+contents);
								}
							});
						},3000
					);
				});
			}
			
			
			checkElement.slideDown('slow',function() {
				
				setTimeout(
					function() { 
						$.ajax({
							url: newurl,
							data: "GET",
							async: false,
							success: function(contents) {
								$("#content").empty().append("<br />"+contents);
							}
						});
					},3000
				);
			});
			
			//return false;
		}
		else {
			setTimeout(
				function() { 
					$.ajax({
						url: newurl,
						data: "GET",
						async: false,
						success: function(contents) {
							$("#content").empty().append("<br />"+contents);
						}
					});
				},3000
			);
		}
		makeSame();
		$("ul.thecategory").hide().show();
		
		return false;
	});
}

function initMenu_user() {
	$('ul.thecategory ul').hide();
	
	$('ul.thecategory li a').click(function() {
		var checkElement = $(this).next();
		
		// activestate
		$(".activestate").each(function() {
			$(this).removeClass("activestate");
		});
		$(this).addClass("activestate");
		
		
		if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			checkElement.slideDown('slow');
			return false;
		}
		else if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
			return true;
		}
		else return true;
		
	});
}

function makeSame() {
	var sidebar = $("#sidebar").height();
	var content = $("#thecontent").height();
	
	var total = sidebar - content;
	
	if(total > 0) {
		jQuery("#thecontent").css({position:"relative",paddingBottom:total+10+"px"});
		jQuery("#footer").css({position:"absolute",bottom:"0px",height:"50px",width:"760px"});
	}
}

function GetAjaxData(newurl) {
	
}

function activeMenu() {
	var i = 1;
	jQuery(".modules li.active:first").parents("ul").addClass("ulparent");
	jQuery("ul.ulparent").parents("li").addClass("liparent");
	jQuery(".liparent a:first").addClass("active");
}

$(document).ready(function() {
	
	$("ul.thecategory ul").each(function() {
		var obj = jQuery(this);
		var total = obj.parents("ul").length;
		obj.addClass("level-"+total);
	});
	
	if($(".there-is-user").length > 0) initMenu_user();
	else initMenu();
	
	activeMenu();

});
