$(document).ready(function() {
	
	$("a.c").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut': 0,
		'overlayShow':	true,
		'overlayOpacity': 0.8,
		'frameWidth': 680,
		'frameHeight': 490
	});	
	//$("a.c").click(loadShowcaseVideo);
	
	$("a.d").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut': 0,
		'overlayShow':	true,
		'overlayOpacity': 0.8,
		'frameWidth': 680,
		'frameHeight': 420
	});
	$("a.t").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut': 0,
		'overlayShow':	true,
		'overlayOpacity': 0.8,
		'frameWidth': 480,
		'frameHeight': 600
	});
	
	$('#tv_produced').cycle({ 
	    fx:     'scrollHorz', 
	    timeout: 0, 
	    next:   '#tvNext', 
	    prev:   '#tvPrev' 
	});
    $('#tv_produced, #tvNext, #tvPrev').hover(
        function() { $('#tvNext').css("display", "block");$('#tvPrev').css("display", "block"); },
        function() { $('#tvNext').css("display", "none");$('#tvPrev').css("display", "none"); }
    );
	
	$("#directorsBar").accordion({ 
		autoHeight: false,
		active: ".current"
	});
	
	
	$(".showcase, .thumb").hover(function () {
		$(this).children(":first").show();
    }, function () {
      $(this).children(":first").hide();
    });
	
	
	$("#clientstable").tablesorter({sortList:[[0,0],[2,0]], widgets: ['zebra']});
		
	$(".folder").hover(function(){
		$(this).css('background', 'red');
	}, function(){
		$(this).css('border', 'none');
	});
});

function loadShowcaseVideo(j) {
	
	$("div.videopopup").each(function(i) {
		if(i==j) {
			i = $(this).attr('i');
			$obj = $("div#sc"+i+" div.videocontainer");
			v = $(this).attr('video');
			if($obj.html()=="" && v!=undefined) {
				s = QT_WriteOBJECT(
					"/files/"+v, "640", "360", "",
					"scale", "tofit",
					"autoplay", "true",
					"controler", "true",
					"loop", "false"
				);
				$obj.html(s);
			}
		}
	});
	
	//s = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="360" width="640"><param name="src" value="/files/'+v+'"><param name="autoplay" value="true"><param name="controller" value="true"><param name="wmode" value="opaque"><param name="scale" value="tofit"><embed height="360" width="640" src="/files/'+v+'" pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" controller="true" autoplay="true" wmode="opaque" scale="tofit"></object>';
	/*$obj = $("div#sc"+i+" div.videocontainer");
	if($obj.html()=="") {
		s = QT_WriteOBJECT(
			"/files/"+$(this).attr('video'), "640", "360", "",
			"scale", "tofit",
			"autoplay", "true",
			"controler", "true",
			"loop", "false"
		);
		$obj.html(s);
	}*/
	return(true);
}

function nowCat() {
	var hash = location.hash;
	if (!hash) return -1;
	hash = hash.replace(/^.*#/, '');
	hash = hash.replace(/\,(\d*)/, '');
	if (isNaN(hash)) return -1;
	return (+hash);
}

var logincheck = false;
function loginClientAccess()
{
	if (logincheck) return false;
	logincheck = true;
	var username = $("#username").val();
	var password = $("#password").val();
	$.ajax({
		type: "POST",
		url: "/clientaccess.php",
		data: "username=" + username + "&password=" + password,
		success: function(msg){
			if(msg==1)
			{
				$.ajax({
					type: "POST",
					url: "/clientaccess.php",
					data: "folder=" + nowCat(),
					success: function(access){
						$("#clientaccess").html(access);
						loggedin = true;
					}
				});
			}else
			{
				alert('Wrong username or password.\nClick OK to continue.');
				setTimeout("logincheck=false;",100);
			}
		}
	});
	return false;
}

function logoutClientAccess()
{
	$.ajax({
		type: "POST",
		url: "/clientaccess.php",
		data: "logout=true",
		success: function(msg){
			$("#clientaccess").html(msg);
			loggedin = false;
		}
	});
}


function folderClientAccess(folder)
{

	$.ajax({
		type: "POST",
		url: "/clientaccess.php",
		data: "folder=" + folder,
		success: function(msg){
			$("#clientaccess").html(msg);
		}
	});
}