/*******************************************************




*******************************************************/








// dialog function 
// this fucntion allows you to load any element into the UI jquery dialog
// @param string div the jquery style name of the div (example " #my div" or ".theDiv")
// @param string url the url to be loaded into the specified div
// @param string callback_function optional naem of the funtion to be called when the dialog closes
	 	function showDialog(div,url,callback_function) {
	 		//try {
	 			// set the default options
	 			var options = {
	 				autoOpen : false, 	// do not open by itself, it would cause to be oopened only once per page
	 				hide:'slide', 		// slide out
	 				open:'slide',		// slide in
	 				position:'top',		// show at the top of the page
	 				modal : true, 		// make it modal - no other things while the form is up there
	 				width:800 			// make it 500px wide
	 				
	 				
	 			};
	 			// add the callback function
	 			if(typeof(callback_function) !== undefined) {
	 				options.close = callback_function;
	 			}
	 			
	 			loadPage(url,div);
	 			
	 			// set the default options
	 			$(div).dialog(options);
	 			// open the window
	 			$(div).dialog('open');
	 			
	 		//}catch(err) {
	 		//	alert("Error occurred (showDialog Function) " + err.description);
	 		//}
	 	}

function showEvent(id) {
	showDialog('#dialog','/prototype/show_event/' + id);
}
	 	
	 	
// this funtion closes the dialog on provided div
// $param string div name of the div on which the dialog should be closed	 	
function closeDialog(div) {
	if($(div).dialog('isOpen')) $(div).dialog('close');
}


 /**
  * this function loads the url into specified div
  *  @param  string url 
  *  @return void
  */
 function loadPage(url, div) {
 	try {
 		var html = getLoadingHtmlString();
 		$(div).html(html);
 		
 		$(div).load(url);
 	}catch(err) {
 		alert("Error (LoadPage) : " + err.description);
 	}
 }
 
 
 
 /**
  * function to update the div with returned html from ajax call
  * it automatically sends the form enclosed in the div
  * @param string div - the dom id of the div to updated
  * @param function name place the callback function name here (without the tailing brackets)
  * @return void
  */
 function updateFormDiv(div, callback_function) {
 	try {
	 	
	 	
	 	var options = {
	 		url : $(div + " form").attr('action'),
	 		success : 
	 		
	 		function(data) 
	 			{
	 				try 
	 				{
		 				$(div).html(data);
		 				if(typeof(callback_function) != 'undefined') 
		 				{
		 					// run the callback function
		 					callback_function();
		 				}	
		 			}catch(err) {
		 				alert("Error : "+ err.description);
		 			}	
	 			}
	 		
	 			
	 			
	 	};//end of options
	 	
	 	
	 	
	 	$(div + " form").ajaxSubmit(options);
	 }catch(err) {
	 	alert("Error (updateDiv) " + err.description);
	}	
 }	 	
 
 function hideElement(div,hide){
 	if(!hide) {
 		
 		$(div).show("slow");
 	}else {
 		$(div).hide("slow");
 	}	
 }
 
 
 
  /**
  * returns html code that is displays while ajax content is loaded
  * it shows ":Loading" adn spinning gif
  * @return string $html the html code 
  */
 function getLoadingHtmlString() {
	 var html = "";
	 try {
	 html += '<div align="center" class="centered">';
	 html += 'Loading ....<br /><br />';
	 html +='<img src="/img/loading.gif"';
	 html += '<br /><br />';
	 html += 'please wait ...';
	 html +='</div>'
	 }catch(err) {
		alert("Error in getLoadingHtmlString function : " + err);
	}
	 return html;
 }
 
 
 
 
 function writeVideoPlayer(divID,width,height) {
 // Video player
	
	if($('#' + divID).length != 0) {
		var vidPlayer = new SWFObject("/flash/player_v416.swf", "videoPlayer", width, height, "8", "#6699CC");
		vidPlayer.addParam('allowscriptaccess','always');
	  	vidPlayer.addParam('allowfullscreen','true');
	  	vidPlayer.addParam('autostart','false');
	  	/* Default movie and picture */
	  	
	  	/*
	  	var image = "/video/fox-news-logo.jpg";
	  	// get the subdomain name and if it is foxbiz , change the logo image
	  	if(get_subdomain()=="foxbiz") image ="/video/fox-biz-logo.jpg"
	  	vidPlayer.addParam('flashvars','&file=/video/20051210-w50s_56K.flv&image=' + image);
	  	vidPlayer.addVariable('javascriptid','videoPlayer');
	  	vidPlayer.addVariable('enablejs','true');
	  	//vidPlayer.addVariable("linktarget", "_self");
	  	*/
		vidPlayer.write(divID);
	}
 
 }
 
 
 
 $(document).ready(function(){
 	
 	
 	$('.listings_search_form form').submit(function(){
 			
 			//hideElement('.listings_search_form',true);
 			hideElement('#divListingsResults',true); // hide
 			loadPage('/prototype/search_results','#divListingsResults');
 			hideElement('#divListingsResults',false); //show
 			return false;
 	});
 	
 	$('.btn_refine_search').click(function(){
 			
 			//hideElement('.listings_search_form',false);
 			hideElement('#divListingsResults',true); //show
 			loadPage('/prototype/show_sponsors','#divListingsResults');
 			hideElement('#divListingsResults',false); //show
 	});
 	
 	$(".show_dialog").click(function(){
 		//showDialog(this,"/prototype/show_profile");
 		alert(this.name);
 	});
 	
 	
 	
 });