$(document).ready(function() { 
    
    // activate the modal overlay
    
    // generate popups for global nav items
                      
    $("a[@rel=popup], area[@rel=popup]").click(function(){
           popupWindow = window.open(this.href,this.title,'menu=no,toolbar=no,width=500,height=600,scrollbars=1,resizable=0,directories=no,location=no,screenX=0,screenY=0,top=48,left=48');
           popupWindow.focus()
           return false;
    })

    $("a[@rel=external], area[@rel=external]").click(function(){
           popupWindow = window.open(this.href,this.title,'toolbar=yes,status=yes,location=yes,menubar=yes,directories=yes,resizable=yes,scrollbars=yes');
           popupWindow.focus()
           return false;
    })
    
    // submit user's flash version with the FAQ form
    
    var flash = deconcept.SWFObjectUtil.getPlayerVersion();
    $("input#flash").val(flash.major + '.' + flash.minor + '.' + flash.rev);
    
    // Popup window close button
    
    $("#popup_close_button").css("cursor","pointer");
    
    $("#popup_close_button").click(function() {
        window.close();
    });
    
    // Un-comment for prechecked Opt-ins
    
    /*
        if (!$("div").hasClass("error")) {
            $("input[@name=primary_opt_in]").attr("checked", "checked");
        }
    */
	
	// Dropdown Menus
	
	$("ul.dropdown li").hover(function(){
    
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    
    }, function(){
    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    
    });
	
	$("#essence #video_thumbs a").each(function(i,elem) {
		$(elem).bind("click", function(e) {
			loadVideo($(this).attr('video_num'));
			
			var this_id = $(this).attr('id');
			
			$("#"+this_id+"_caption").show();
			
			$("#essence #video_thumbs a[orig_src]").each(function(i,other_elem) {
				$(other_elem).children("img").attr('src',$(other_elem).attr('orig_src'));
				$(other_elem).removeAttr('orig_src');
				
				$("#"+$(other_elem).attr('id')+"_caption").hide();
			});
			
			var this_image = $("#"+this_id+" img");
			
			var orig_src = this_image.attr('src');
			this_image.attr('src',"public/images/"+this_id+"_ro.jpg");
			
			$(this).attr("orig_src",orig_src);
			
			e.preventDefault();
		});
	});
	
});       


function loadVideo ( num ) {

			videoswf = new SWFObject("public/media/video.swf", "videoswf", "600", "400", "10.0", "#000000");

			  videoswf.addParam("menu", "false");
			  videoswf.addParam("quality", "high");
			  videoswf.addParam("wmode", "transparent");
			  videoswf.addParam("allowFullScreen","true");
			  videoswf.addParam("AllowScriptAccess","always");
			  videoswf.addVariable("vid_src","rtmp://stream.eprize.net/ondemand/flash/cocacola/stepoff/video2_"+num+".flv");
			  videoswf.write("flash_video");

}
 

