var enter_email_def; 
var enter_fname_def; 
var enter_lname_def; 
$(document).ready(function()
{    
	$('#flashMarquee img').fadeIn();
    $("ul.sf-menu").superfish({ 
            delay:       800
        });
		
    $("#emailFormDDClose").click(function()
    {        
        $("#emailFormDD").slideUp("fast");    
    });        
    enter_email_def = $("#headerEmailField").attr("value");        
    $("#headerEmailField").focus(function()
    {        
        if ($("#headerEmailField").attr("value") == enter_email_def)        
        {            
            $("#headerEmailField").attr("value", "");        
        }        
        $("#emailFormDD").slideDown("fast");    
    });
    $("#headerEmailField").blur(function()
    {        
        if ($("#headerEmailField").attr("value") == "")        
        {            
            $("#headerEmailField").attr("value", enter_email_def);        
        }
    }); 
	
    enter_fname_def = $("#headerFNameField").attr("value"); 
	$("#headerFNameField").focus(function()
    {        
        if ($("#headerFNameField").attr("value") == enter_fname_def)        
        {            
            $("#headerFNameField").attr("value", "");        
        }          
    });
    $("#headerFNameField").blur(function()
    {        
        if ($("#headerFNameField").attr("value") == "")        
        {            
            $("#headerFNameField").attr("value", enter_fname_def);        
        }
    }); 
	
    enter_lname_def = $("#headerLNameField").attr("value"); 
	$("#headerLNameField").focus(function()
    {        
        if ($("#headerLNameField").attr("value") == enter_lname_def)        
        {            
            $("#headerLNameField").attr("value", "");        
        }          
    });
    $("#headerLNameField").blur(function()
    {        
        if ($("#headerLNameField").attr("value") == "")        
        {            
            $("#headerLNameField").attr("value", enter_lname_def);        
        }
    });         
$('#headerEmailSubmit').click(function()
    {
        if ($("#headerEmailField").attr("value") != enter_email_def && $("#headerFNameField").attr("value") != enter_fname_def && $("#headerLNameField").attr("value") != enter_lname_def)
        {
        
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
 
        var emailaddressVal = $("#headerEmailField").val();
        if(emailaddressVal == '') {
        alert("An email address is required!")
        }
 
        else if(!emailReg.test(emailaddressVal)) {
        alert("A valid email address is required!")
        }
        
		else if($("#headerFNameField").attr("value") == ""){
			alert("A First Name is required!")
            //No First Name :(
        }
		else if($("#headerLNameField").attr("value") == ""){
	        alert("A Last Name is required!")
            //No Last Name :(
        }
        else{
        
        // stransky 13mar11 - correcting mistakes. checkboxes dont have values the way traditional form fields do so this was forcing all subsribers to opt in for everything
        $.post("subscribe.php", { name: $('#headerEmailField').attr("value")
                                  ,fname: $("#headerFNameField").attr("value") 
                                  ,lname: $("#headerLNameField").attr("value") 

                                  ,events: $("#headerEmailEvents").attr("checked") 
                                  ,volunteer: $("#headerEmailVolunteer").attr("checked") 
                                  ,news: $("#headerEmailNews").attr("checked") 
                                  ,legislature: $("#headerEmailLegislature").attr("checked") 
                                  /*
                                  ,events: $("#headerEmailEvents").attr("value") 
                                  ,volunteer: $("#headerEmailVolunteer").attr("value") 
                                  ,news: $("#headerEmailNews").attr("value") 
                                  ,legislature: $("#headerEmailLegislature").attr("value") 
                                  */
                                  
                                }
                              ,function(){ $("#emailFormDD").slideUp("fast"); $('#headerSignupForm').hide();$('#headerThankYou').show();} 
                      );                      
            }
        }    
        else
        { 
        	alert("All fields are required!")                       
        }
        return false;            
    
    $('#flashMarquee').cycle();
    $("#video").dialog({ autoOpen: false, width: 600, modal: true, show: 'scale',  resizable: false, open: stopMarquee, close: stopVideo });   
    $("#slideshow").dialog({ autoOpen: false, width: 875, height: 600, modal: true,  resizable: false });         
});

	$("#overlay").live('click',function(){
		$("#slideshow").hide();
		hideOverlay();
	});
	
	$(".slideshow_close").live('click',function(){
		  $("#slideshow").hide();
                hideOverlay();
		
	});

        $(".video_close").live('click',function(){
                stopVideo(); 
		 $("#video").hide();
                hideOverlay();

        });


});

    jQuery.fn.center = function () {
        this.css("position","absolute");
//alert($(window).height());
        this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
        this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
        return this;
    }

	function showOverlay() {
	        var docHeight = $(document).height();
        	$("body").append('<div id="overlay"></div>');
	        $("#overlay").height(docHeight).show();
	}
	
	 function hideOverlay() {
		$("#overlay").remove();
	}


function openVideoDialog(movieLocation)
{
	var flashvars = {
		skin: "/themes/agassi/flash/whiteSkinOverPlayStopSeekMuteVol.swf",
		callback: "videoSize",
		path: movieLocation
	};
	
	var params = { allowscriptaccess: "always", scale: "noscale", wmode: "transparent" }
	showOverlay();
    swfobject.embedSWF("/themes/agassi/flash/masterVideoPlayer.swf", "videoPlayer", "500", "300", "8.0.0", "/assets/expressInstall.swf", flashvars, params);
    $("#video").show('fast',function(){$("#video").center()}); 
}

function videoSize(width, height)
{
	var message = "video size called " + width + "x" + height;
	console.log(message);
	$('#videoPlayer').css('width', width);
	$('#videoPlayer').css('height', height);
	$('#video').css('width', width);
	$('#video').css('height', height);
	$('#video').dialog( 'option' , 'width' , width+36 );
}

function openSlideshowDialog(xmlLocation, imageLocation)
{         
	showOverlay();
	swfobject.embedSWF("/themes/agassi/flash/slideshow.swf?xmlPath=" + xmlLocation + "&prefixPath=" + imageLocation, "slideshowPlayer", "848", "504", "8.0.0", "/assets/expressInstall.swf", {}, {allowscriptaccess:"always",wmode:"opaque"});
	$("#slideshow").show('fast',function(){$("#slideshow").center()});
}

function thisMovie(movieName) 
{
    if (navigator.appName.indexOf("Microsoft") != -1) 
    {
        return window[movieName];
    } 
    else 
    {
        return document[movieName];
    }
}
function setVideo(value) 
{
    thisMovie("videoPlayer").setMediaPath(value);
} 
function stopMarquee()
{
    try
    {
        thisMovie("flashMarquee").setStop('null');
    }
    catch(err)
    {
    }
}
function stopVideo()
{
    swfobject.embedSWF("/themes/agassi/flash/media_560_335.swf", "videoPlayer", "560", "335", "8.0.0", "/assets/expressInstall.swf", {}, {allowscriptaccess:"always"});
    return false;
}


