// JavaScript Document

var baseURL='/';

// Ajax Calendar Variables
var curDate=new Date();
var cal_curMonth = parseInt(curDate.getMonth()+1);
var cal_curYear = parseInt(curDate.getFullYear());
var cal_monthNames = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

jQuery.fn.center = function () {
    this.css("position","absolute");
    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 listing_highlight_prepare(clickable) {
	
	if (clickable==undefined) {clickable=true;}
	
	// The hover event
	$(".table_row.highlight").hover(function () {
      								$(this).css({'background-color' : '#e7e7e7', 'cursor' : 'pointer'});
									$(this).find('img.listing_star').show();
									
    							}, function () {
									  $(this).css({'background-color' : 'transparent', 'cursor' : 'default'});
									  $(this).find('img.listing_star').hide("fast");
    });
	  
	if (clickable == true) {
		$(".table_row.highlight").click(function () {
			document.location=$(this).find("input[type='hidden']:first").val(); 
		});
	}
	  
	  // Hide the stars
	  $(".listing_star").hide();
	
}


function initialize() {


	$("#search_textbox").keypress(function (e) {
      if(e.which==13) {
		document.location="/index.php/search/results/"+$("#search_textbox").val(); 
	  }
    });

	// clear on focus
	$("#search_textbox").focus(function () {
			if ($(this).val()=="SEARCH") {
				$(this).val(""); 
			}
	});


}


function listing_membership_levels_prepare() {
	
	// The hover event
	$(".table_row.highlight").hover(function () {
      								$(this).css({'background-color' : '#e7e7e7', 'cursor' : 'pointer'});
									$(this).find('img.listing_star').show();
									
									// setting the texts
									$("#level_title").html($(this).find("input[type='hidden']:eq(1)").val());
									$("#level_text").html($(this).find("input[type='hidden']:eq(2)").val());
									
    							}, function () {
									  $(this).css({'background-color' : 'transparent', 'cursor' : 'default'});
									  $(this).find('img.listing_star').hide("fast");
    });
	  
	
	
	
	  
	$(".table_row.highlight").click(function () {
		
		link_to_open = $(this).find("input[type='hidden']:first").val();
		
		// open the popup
		openExternalURL(link_to_open);
		
		/*
		
		// loading the texts
		$("#level_text").html('<iframe name="iwindow" scrolling=auto width=100% height=610 scrolling=no align=top frameborder=0 src="'+link_to_open+'"></iframe>');
		//document.location=$(this).find("input[type='hidden']:first").val(); 
		*/
		
		
		
		
		
	});
	  
	  // Hide the stars
	  $(".listing_star").hide();
	
}


function getCalendarPopup(date) {
	
	
	$.post(baseURL+"index.php/ajax/getCalendarDate/"+date, { 
		date: date 
		},
  	function(data){

    	//alert('CurrentActivePopupId = '+CurrentActivePopupId);
    
    		$("#Calendar #popup #content").html(data);
		 	// centering the popup
		 	$("#Calendar #popup").center();
         	$("#Calendar #popup").css({'z-index':'1000'});
         	$("#Calendar #popup").css({'width':'370px'});
         	$("#Calendar #popup").fadeIn("fast");
    
    	
  	});


	
	// ---------------------------------------------------------
	// Adding the close action
	$("#Calendar #popup #close_link").click(function () {
      $("#Calendar #popup").fadeOut("fast");
    }); 
	// ---------------------------------------------------------
	
	

}


function getCalendarHTML(month,year) {
	
	$.post(baseURL+"index.php/ajax/getCalendarHTMLElements/"+month+"/"+year, {},
  	function(data){

    		$("#Calendar #Elements").html(data);
    	
  	});
  	
  	

	// ---------------------------------------------------------
	// Adding the close action
	$("#Calendar #Dates #Title #curMonthName").html(cal_monthNames[month-1]); 
	// ---------------------------------------------------------
	
}


function getNextCalendar() {

	cal_curMonth = parseInt(cal_curMonth)+1;
	if (cal_curMonth==13) {
		cal_curMonth=1;
		cal_curYear=parseInt(cal_curYear)+1;
	}
	
	// call the ajax calendar
	getCalendarHTML(cal_curMonth,cal_curYear);

}

function getPrevCalendar() {

	cal_curMonth = parseInt(cal_curMonth)-1;
	if (cal_curMonth==0) {
		cal_curMonth=12;
		cal_curYear=parseInt(cal_curYear)-1;
	}
	
	// call the ajax calendar
	getCalendarHTML(cal_curMonth,cal_curYear);

}


// -------------------------------------------------------------
// Gallery/Player Widget
function createPlayer(theFile,destinationDiv,width,height,thumb,autostart,logo,playlist) {
	
	// The thumb extention
	if (thumb != "") {thumb_string="&image="+thumb;} else {thumb_string="";}
	
	// The logo extention
	if (logo != "") {logo_string="&logo="+logo;} else {logo_string="";}
	
	var s1 = new SWFObject(baseURL+'images/player.swf','player',width,height,'9');
	s1.addParam('allowfullscreen','true');
	s1.addParam('allowscriptaccess','always');
	s1.addParam('wmode','transparent');
	if (playlist!="") {
		// we have a playlist
		s1.addParam('flashvars','file='+playlist+thumb_string+autostart+"&repeat=true&shuffle=false"+logo_string+"&skin="+baseURL+"images/stylish.swf");
	} else {
		// we DONT have a playlist
		s1.addParam('flashvars','file='+theFile+thumb_string+autostart+"&repeat=true&shuffle=false"+logo_string+"&skin="+baseURL+"images/stylish.swf");
	}
	s1.write(destinationDiv);

	//var player = document.getElementById("player");
	  
	
}

// -------------------------------------------------------------

	function openExternalURL(url) {
		
		
		msg = '<iframe width="100%" scrolling="auto" height="610" frameborder="0" align="top" src="'+url+'" name="iwindow"/></iframe>';
		
		 //alert(msg);
		 $("#Calendar #popup #content").html(msg);
		 // centering the popup
		 $('#Calendar #popup').center();
		 $("#Calendar #popup").css({'z-index':'1000'});
		 $("#Calendar #popup").css({'width':'770px'});
 		$("#Calendar #popup").css({'left':'222px'});
		 $("#Calendar #popup").fadeIn("fast");
		
	
		
		// ---------------------------------------------------------
		// Adding the close action
		$("#Calendar #popup #close_link").click(function () {
		$("#Calendar #popup").fadeOut("fast");
		}); 
		// ---------------------------------------------------------
		
		
	}


// -------------------------------------------------------------

var player;

function playerReady(obj) {
	
	player = document.getElementsByName(obj.id)[0];
	
};

function loadNplay(file) {
	player.sendEvent('LOAD', {file:file});
	player.sendEvent('PLAY', 'true');
};

