var isHome = 0;

$(document).ready(function(){
	// HOME PAGE SCROLLING
	$("#mainContent").smoothDivScroll({
		autoScroll: "onstart",
		autoScrollDirection: "backandforth",
		autoScrollStep: 1,
		autoScrollInterval: 15,
		startAtElementId: "startAtMe",
		visibleHotSpots: "onstart", // onstart or always
		hotSpotsVisibleTime: 5, // IF onstart
		ajaxContentURL: "backgroundLoad.php"
	});
	
	// HIDE NEWS
	$("#news").hide();
	
	// BACKGROUND SCROLLING
	/*$("#mainContent").mouseout(function() {
		if(isHome==1){
			$("#mainContent").smoothDivScroll("startAutoScroll");
		}
	});*/
	
	// SHOW SUBMENU
	$(".menuTop").mouseover(function() {
		$(this).children(".menuSub").show();
	}).mouseout(function() {
		$(this).children(".menuSub").hide();
	});
});

function Home(){
	isHome = 1;
	// HIDE SCROLLER & EMPTY
	$("#scrollingContent").empty();
	$("#scrollingContent").hide();
	// HIDE BOX
	$("#box").hide(400);
	// HIDE NEWS
	$("#news").hide(400);
	// HIDE BRAND PAGE
	$("#brand").hide(400);
	// SHOW HOME
	$("#mainContent").show();
	$("#mainContent").smoothDivScroll("startAutoScroll");
	
	return false;
}

function contactUs(){
	email = $("#email").val();
	comment = $("#comment").val();
	if(email!="" && comment!=""){
		$("#loader").show();
		$.post("exe.php",{ email: email, comment: comment, action: "contactUs" }, function(data){
			$("#contactUsResult").html(data);
			$("#loader").hide();
		});
	}else{
		alert("Мэдээлэл дутуу!");
	}
}

function Scroll(){
	isHome = 0;
	// HIDE BOX
	$("#box").hide(400);
	// HIDE NEWS
	$("#news").hide(400);
	// HIDE BRAND PAGE
	$("#brand").hide(400);
	// SHOW HOME & STOP
	$("#mainContent").show();
	$("#mainContent").smoothDivScroll("stopAutoScroll");
	// SHOW SCROLLER
	$("#loader").show();
	$("#scrollingContent").show();
	$.post("scroll.php",function(data){
		$("#scrollingContent").html(data);
		$("#loader").hide();
	});
	
	return false;
}

function Brand(id){
	isHome = 0;
	// HIDE BOX
	$("#box").hide(400);
	// HIDE NEWS
	$("#news").hide(400);
	// HIDE SCROLLER & EMPTY
	$("#scrollingContent").empty();
	$("#scrollingContent").hide();
	// HIDE HOME & STOP
	$("#mainContent").smoothDivScroll("stopAutoScroll");
	$("#mainContent").hide();
	// SHOW BRAND PAGE
	$("#loader").show();
	$("#brand").show();
	$.post("brand.php",{ id: id }, function(data){
		$("#brand").html(data);
		$("#loader").hide();
	});
	
	return false;
}

function isNumber (num) {
	return ! isNaN (num-0);
}

function Box(id){
	isHome = 0;
	var page = "newsMore";
	// HIDE NEWS
	$("#news").hide(400);
	// HIDE SCROLLER & EMPTY
	$("#scrollingContent").empty();
	$("#scrollingContent").hide();
	// HIDE BRAND PAGE
	$("#brand").hide(400);
	// HIDE HOME & STOP
	$("#mainContent").show();
	$("#mainContent").smoothDivScroll("stopAutoScroll");
	
	// SHOW BOX	
	$("#loader").show();
	$("#box").html("");
	
	if(!isNumber(id)){
		page = id;
	}
	
	$.post(page + ".php",{ id: id }, function(data){
		$("#box").html(data);
		$("#loader").hide();
	});
	$("#box").show(400);
}

function Category(id){
	isHome = 0;	
	// HIDE SCROLLER & EMPTY
	$("#scrollingContent").empty();
	$("#scrollingContent").hide();
	// HIDE BRAND PAGE
	$("#brand").hide(400);
	// HIDE HOME & STOP
	$("#mainContent").show();
	$("#mainContent").smoothDivScroll("stopAutoScroll");
	// HIDE BOX
	$("#box").hide(400);
	
	// SHOW NEWS
	$("#loader").show();
	$("#news").show(400);
	
	$.post("news.php",{ id: id }, function(data){
		$("#news").html(data);
		$("#loader").hide();
	});
}

// *************** HASHCHANGE START *************** 
$(function(){	
	// Bind an event to window.onhashchange that, when the hash changes, gets the
	// hash and adds the class "selected" to any matching nav link.
	$(window).hashchange( function(){
		var hash = location.hash;
		
		var urlStr = ( hash.replace( /^#/, '' ) || 'Home' );
		//var urlStr = hash.replace( /^#/, '' );
		var temp = new Array();
		temp = urlStr.split('/');
				
		eval( temp[0] )( temp[1], temp[2], temp[3], temp[4], temp[5] );

	})
	// Since the event is only triggered when the hash changes, we need to trigger
	// the event now, to handle the hash the page may have loaded with.
	$(window).hashchange();
});
// *************** HASHCHANGE END *************** 

