var prevSection;

// goddess_gospels.js
function closeProducts() {
	$("#video_products").slideUp("slow");
	$("#open_products").slideDown("slow");
}

$(document).ready(function() {
	var read_how = $("#open_products a").text();
	// vars for flash player
	var flashvars = {
		lan:'en'
	};
	var params = { allowfullscreen:"true", scale: "showall",  allowScriptAccess: "sameDomain" };
	var attributes = {};
	
	
	$('.video_link li a').click(function(){
		var flashHolder = $(this).parent('li').parent('ul').next('div');
		if( prevSection != flashHolder.attr('id') ){							 
			$('div.hasFlash').removeClass('hasFlash').slideUp();
		}
		
		// get video info
		var video_title = $(this).text();
		var video_title_lowercase = video_title.toLowerCase();
		
		// get the ID of the flash container
		var url = $(this).attr('href');
		var regex = /\/(.[^\/]*)(_es|_de|_it)?\.flv/;
		var tmp = url.match(regex);
		var div_id = tmp[1];
		
		//20090610-Dan-Hack to remove _es from url.  For some reason _de and _it
		//are removing from url fine but _es isnt been removed using above method.
		//as a quick fix I am using another step to remove _es from div_id.
		div_id = div_id.replace(/_es/,"");
		
		if( div_id == 'camera_cafe1') { div_id = 'camera_cafe1' };
		if( div_id == 'camera_cafe2') { div_id = 'camera_cafe2' };
		if( div_id == 'camera_cafe3') { div_id = 'camera_cafe3' };
		if( div_id == 'camera_cafe4') { div_id = 'camera_cafe4' };
		if( div_id == 'camera_cafe5') { div_id = 'camera_cafe5' };

		
		
		
		
		$("#video_title").text(video_title);
		
		swfobject.embedSWF(url, "flash_item", "507", "317", "9.0.0","/js/expressInstall.swf", flashvars, params, attributes);

		flashHolder.addClass('hasFlash').append( $("#flash_content") );
		
		// add the flash and open container
		$(".hiddenproducts").hide();
		if( flashHolder.attr('id') != 'flash_fashion_videos' ){
			closeProducts();
			$('#open_products a').text(read_how.replace("_lookname_",video_title_lowercase));
			$('#open_products').show();
			$('#' + div_id).show();
		} else {
			$('#open_products').hide();
		}
		
		flashHolder.slideDown('slow');
		
		prevSection = flashHolder.attr('id');
		
		return false;
	});
	
	$("#open_products a").click(function() {
		$("#video_products").slideDown("slow");
		$("#open_products").slideUp("slow");
		return false;
	});
	$(".close_products").click(function() {
		closeProducts();
		return false;
	});
});