$(document).ready(function() {
	//menu
  	jQuery('ul.sf-menu').superfish();
	
	//hiding of the left nav
	/*if($(".secondary-nav").length != 0 )
	{
		if($(".secondary-nav").children().length == 0)
		{
			$(".right-col").hide();
			$(".secondary-nav-header").hide();
			$(".secondary-nav").hide();
			$(".left-col").addClass("wide");
		}
	}*/
	
	if($("#schedule-appointment").length != 0 )
	{
		$("#schedule-appointment").validate();
		 $("#schedule-appointment .submit").click(function()
		  {        
			  if ($("#schedule-appointment").valid())
			  {            
				var name = $('#name').val();
				var email = $('#email').val();
				var phone = $('#phone').val();
				var reason = $("#reason").val();
				//var verif_box=$("#verif_box").val();
						 
				$.ajax(
				{
				  url : "/send.php",
				  type: "POST",
				  data: "name=" + name + "&email=" + email + "&phone=" + phone + "&reason=" + reason,//+'&verif_box='+verif_box,
				  success:function(data)
				  {    
				  	if(data.indexOf("errorcaptcha")>-1){
						alert("Validation number is not valid.");
						return;	
					}
					$("#schedule-appointment").hide().html("").html("<div class='confirmation'>Your appointment has been sent!</div>").fadeIn(500);
					//alert(data);
				  }
				  //,
				//  error:function(data)
				 // {   
				//	alert("error");
				  //}
				});
			  }
			
			  return false;
	  
		  });
	}
 	
	//gallery
	if($("#gallery").length != 0 )
	{
  		$( "#accordion" ).accordion({ header: 'h2', collapsible: true, autoHeight: false });
		
		//Picture Gallery Handler
		$(".office img").click(function(){
			$( "#dialog:ui-dialog" ).dialog( "destroy" );
	
			//GET IMG SRC
			$("#dialog-modal img").attr("src", "upload/" + $(this).attr("data-image"));
			$( "#dialog-modal" ).dialog({
				width: 780,
				height: 575,
				modal: true,
				resizable: false,
				draggable: false
			});
			//GET TITLE
			$(".ui-dialog-title").html($(this).attr("data-title"));
		});
		
		function renderVideo(url, title)
		{
			$( "#dialog:ui-dialog" ).dialog( "destroy" );
			
			if ( $.browser.msie ) {
				$("#dialog-modal-video p").html('<object tabindex="0" id="widgetID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="500" height="415" title="widgetTitle"><param name="movie" value="' + url + '"/><param name="quality" value="high"/><param name="AllowScriptAccess" value="always"/> <param name="allowFullScreen" value="true" /><param name="FlashVars" value="bg=ffffff"/><img src="http://www.cdc.gov/CDCTV/ObesityEpidemic/ObesityEpidemic.jpg" width="500" height="415" alt="CDC Video Player. Flash Player 9 is required."/><br />CDC Video Player. <br /><a href="http://get.adobe.com/flashplayer/">Flash Player 9 is required.</a></object><a id="end-widget-focus"></a>');
			} else {
				$("#dialog-modal-video p").html('<object tabindex="0" id="widgetID" data="' + url + '" width="500" height="415" type="application/x-shockwave-flash" title="widgetTitle"><param name="quality" value="high"/><param name="AllowScriptAccess" value="always"/> <param name="allowFullScreen" value="true" /> <param name="FlashVars" value="bg=ffffff"/><param name="pluginurl" value="http://get.adobe.com/flashplayer/"/><img src="http://www.cdc.gov/CDCTV/ObesityEpidemic/ObesityEpidemic.jpg" width="500" height="415" alt="CDC Video Player. Flash Player 9 is required."/><br />CDC Video Player. <br /><a href="http://get.adobe.com/flashplayer/">Flash Player 9 is required.</a></object><a id="end-widget-focus"></a>');
			}
			
			$( "#dialog-modal-video" ).dialog({
				width: 528,
				height: 489,
				modal: true,
				resizable: false,
				draggable: false,
				close: function(event, ui)
				{
					$("#dialog-modal-video p").html("");
				}
			});
			//GET TITLE
			$(".ui-dialog-title").html(title);	
		}
		
		//Video Gallery Handler
		$(".video-gallery-item a[data-url]").click(function(){
			renderVideo($(this).attr("data-url"), $(this).attr("data-title"));
		});
		
		var featured = queryString("featured");
		if(featured.toString() != "")
		{
			renderVideo($(".video-gallery-item a[data-featured='true']").attr("data-url"), $(".video-gallery-item a[data-featured='true']").attr("data-title"));
			
		}
		
	}//endGallery
	
	
	//Helper Methods
	
	///Gets 
	function queryString(key) {
	   var re=new RegExp('(?:\\?|&)'+key+'=(.*?)(?=&|$)','gi');
	   var r=[], m;
	   while ((m=re.exec(document.location.search)) != null) r.push(m[1]);
	   return r;
	}	

});

//popup //
function showPopup(url){
	var myWindow;
    var width = 650;
    var height = 650;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "subWind", windowFeatures);
	
}
