// JavaScript Document
$(document).ready(function(){
	var primSect = $("#primSection");
	
	var recentTitle = $("#recentTitle");
	var mostTitle = $("#mostTitle");
	var lengthTitle = $("#lengthTitle");
	
	var sortRecent = $("#recent");
	var sortMView = $("#mostview");
	var sortLength = $("#length");
	var catid = 0;  
	
	//Recent Sort
	sortRecent.click(function(){
		primSect.load("selectCat.php?cat=" + catid + "&sort=dateposted");	
		if(sortRecent.attr("checked") == true){
			recentTitle.addClass("sortCheck");
			mostTitle.removeClass("sortCheck");
			lengthTitle.removeClass("sortCheck");
		}
		$(".title").html("Recently Added");
		
	});
	
	//Most View Sort
	sortMView.click(function(){
		primSect.load("selectCat.php?cat=" + catid + "&sort=totalview");
		if(sortMView.attr("checked") == true){	
			mostTitle.addClass("sortCheck");
			recentTitle.removeClass("sortCheck");
			lengthTitle.removeClass("sortCheck");
		}
		$(".title").html("Most View");
	});
	
	//Length Sort
	sortLength.click(function(){
		primSect.load("selectCat.php?cat=" + catid + "&sort=totalview");
		if(sortLength.attr("checked") == true){
			lengthTitle.addClass("sortCheck");
			recentTitle.removeClass("sortCheck");
			mostTitle.removeClass("sortCheck");
		}
		$(".title").html("Video Length");
		
	});
	
	function recentDefault(){
		$(".title").html("Recently Added");
		recentTitle.addClass("sortCheck");
		mostTitle.removeClass("sortCheck");
		lengthTitle.removeClass("sortCheck");
		$("#recent").attr("checked", "checked");
		$("#all a").removeClass("onCat");
		$("#deco a").removeClass("onCat");
		$("#doodads a").removeClass("onCat");
		$("#games a").removeClass("onCat");
		$("#photo a").removeClass("onCat");	
	}
	
	recentDefault();
	//Default
	primSect.load("selectCat.php");
	$("#all a").addClass("onCat");
	$(".title").html("Recently Added");
	
	
	$("#all a").click(function(){
		loadCat("all");
		primSect.load("selectCat.php?cat=" + catid + "&sort=dateposted");
		recentDefault();
		$("#all a").addClass("onCat");
	});
	
	$("#deco a").click(function(){
		loadCat("deco");
		primSect.load("selectCat.php?cat=" + catid + "&sort=dateposted");
		recentDefault();
		$("#deco a").addClass("onCat");
	});
	
	$("#doodads a").click(function(){
		loadCat("doodads");
		primSect.load("selectCat.php?cat=" + catid + "&sort=dateposted");
		recentDefault();
		$("#doodads a").addClass("onCat");
	});
	
	
	$("#games a").click(function(){
		loadCat("games");
		primSect.load("selectCat.php?cat=" + catid + "&sort=dateposted");
		recentDefault();
		$("#games a").addClass("onCat");
	});
	
	$("#photo a").click(function(){
		loadCat("photo");
		primSect.load("selectCat.php?cat=" + catid + "&sort=dateposted");
		recentDefault();
		$("#photo a").addClass("onCat");
	});
	
	
	function loadCat(cat){
		switch(cat){
			case "all":
				catid = 0;	
			break;
			
			case "deco":
				catid = 2;
			break;
			
			case "doodads":
				catid = 3;
			break;
			
			case "games":
				catid = 4;
			break;
			
			case "photo":
				catid = 5;
			break;
		}
		
	}
	
});
