jQuery(document).ready(function() {
	var loc = window.location;
	var locStr = loc.toString();
	var locIndex = locStr.indexOf("#");
	var vidName = locStr.substring((locIndex + 1));
	
	var flashvars = {
	FLVpath: locIndex == -1 ? '/videos/1930_balboa_ave_del_mar.flv' : ('http://www.psplatinum.com/videos/' + vidName + '.flv')};
	var params = {wmode: "transparent"};
	var attributes = {}; 
    swfobject.embedSWF("videoPlayer640x360.swf", "videoObject", "640", "360", "9.0.0","expressInstall.swf", flashvars, params, attributes);
	
	
	arr = jQuery.makeArray($("#mycarousel a")); 
	var arrNames = [];
	jQuery.each(arr, function () {
		var str = this.toString(); 
		var indexNum = str.indexOf("#");
		var names = str.substring((indexNum + 1)); 
		arrNames.push(names);
	}); 
	var startIndex = jQuery.inArray(vidName, arrNames);
//	alert(startIndex);
    jQuery('#mycarousel').jcarousel({
        vertical: true,
        scroll: 2,
		animation: "slow",
		start: startIndex ? startIndex : 0
    });
	$(".overlay").css({'opacity' : .7});
	$(".logoSm").css({'opacity' : 0});
//	alert(jQuery.inArray(vidName, arrNames));
	if (locIndex == (-1)) { //url has no hash
		$(".first").css({'opacity' : 0});
		$("#mycarousel li:first").addClass("bgMove");
	} else {
		$("#mycarousel li:eq("+startIndex+")").find(".overlay").css({'opacity' : 0});
		$("#mycarousel li:eq("+startIndex+")").addClass("bgMove");
	}
	$("#mycarousel li").hover(function () {
		if ($(this).hasClass("bgMove")) {return;}
		$(this).find(".logoSm").stop().animate({'opacity' : 1}); 
		$(this).find(".overlay").stop().animate({'opacity' : .8}); 
	}, function () {
		if ($(this).hasClass("bgMove")) {return;}
		$(this).find(".logoSm").stop().animate({'opacity' : 0}, "fast");
		$(this).find(".overlay").stop().animate({'opacity' : .7});
	});
	
	$(".overlay").click(function () {
		$(".overlay").not(this).stop().animate({'opacity' : .7}); //all other tns go to B/W
		$(this).stop().animate({'opacity' : 0});
		$(".logoSm").animate({'opacity' : 0}, "fast");
	});
	
	$(".logoSm").click(function () {
		$(".overlay").not(this).stop().animate({'opacity' : .7}); //all other tns go to B/W
		$(this).next().stop().animate({'opacity' : 0});
		$(".logoSm").animate({'opacity' : 0}, "fast");
	});	
	
	$("#mycarousel li").click(function bgMove () {
			$("#mycarousel li").not(this).removeClass("bgMove");
			$(this).addClass("bgMove");
			$(this).find(".overlay").stop().animate({'opacity' : 0});
	});
	
	$("#mycarousel a").click(function () {
		var index = $(this).attr("name");
		$(".addthis_button").fadeOut("fast");
		$("#vidContainer").animate({"opacity" : 0}, 200, function () {	
			$("#videoObject").remove();
			$("#vidContainer").animate({"opacity" : 1}, function () {
				$(".addthis_button").fadeIn();
				$("#vidContainer").load(index + "?random=" + Math.random()*99999); 
			});
		});
	});
});


