$(document).ready(function(){

	$(".external").attr("target","_blank");

	/*$(".transparent").css('opacity','0.9');*/

	$(".back-button").click(function(){
		history.back();									 
	 });
	
	if($(".delete").size()){
		$(".delete").bind("click", confirmDelete);
	}
	
	$(".print").click(function(){
		window.print();									 
	 });

	$("#whats_new_tabs").tabs({
							  	"cache":true,
								"cookie":{ expires: 30 } 
							  });

	$(".clear_text").bind("click",function(){
   		if($(this).hasClass("clear_text")){
			$(this).val("");
			$(this).removeClass("clear_text");
	   }
	});
	
	$("a.gallery-image").fancybox({
		'zoomOpacity' : true,
		'zoomSpeedIn' : 500,
		'zoomSpeedOut' : 500
		});
	
	$("a.fancybox").fancybox({
		'hideOnContentClick': false, 					 
		'zoomOpacity' : true,
		'zoomSpeedIn' : 500,
		'zoomSpeedOut' : 500
		});
	
	$(".protected-access").bind("click",function(){
		$(".protected-login").slideDown();											  
	});
	
	
	//Load Google Maps
	if(typeof load == 'function'){
		load();
	}
	
	if(jQuery.browser.msie){
		//Apply Drop Down Styles for IE 6
		var msie_version = (parseInt(jQuery.browser.version));
		
		if(msie_version == 6){
			$("#navigation ul li").hover(function(){
				$(this).children('ul:first').addClass("msiefix");
				//$("ul#main-nav li.home_nav ul").bgiframe();
			}, function(){
				$(this).children('ul:first').removeClass("msiefix");}
			);
		}
		$('input.calculation[disabled]').removeAttr("disabled").addClass('force_disabled');
	}
	
	$('input.force_disabled,input.calculation[disabled]').css('background-color','#CCCCCC')
				  .css('border','1px solid #999999')
				  .css('color','#FF0000')
				  .css('padding','5px')
				  .bind('keypress',function(){ return false; })
				  .bind('keydown',function(){ return false; })
				  .bind('keyup',function(){ return false; })
				  .bind('select',function(){ $(this).blur(); });
	$('#event_form').submit(function(){ 
			$('#event_form input[disabled]').removeAttr("disabled"); 
	});	
	
	$('.festival_selection').livequery('change',function(){
		id = $(this).attr('id');
		festival_id = $(this).val();
		ids = id.split("_");
		id = ids[2];
		//var alreadyRegistered = false;
		$.ajax({
			type: "POST",
			url: "/includes/ajax.php",
			data: "action=ajaxAlreadyRegistered&id=" + id + "&festival_id=" + festival_id,
			success: function(html){   
				if(html == "full"){
					if(id == undefined){
						idAppend = "";	
					}else{
						idAppend = "_" + id;
					}
					$("#festival_housing_drop_down" + idAppend).html('<p class="failure">Sorry! But the site has reached capacity. We are unable to accept any additional transfers.</p>').slideDown();
				}else if(html == "true"){
					if(id == undefined){
						idAppend = "";	
					}else{
						idAppend = "_" + id;
					}
					$("#festival_housing_drop_down" + idAppend).html('<p class="failure">Already Registered<br />If you need to make any changes<br />please <a href="/festival-registration/list" style="color:#000000;">click here</a>.</p>').slideDown();
				}else{
					
					$.ajax({
					   type: "POST",
					   url: "/includes/ajax.php",
					   data: "action=ajaxGetFestivalHousing&id=" + id + "&festival_id=" + festival_id,
					   success: function(html){
							if(id == undefined){
								idAppend = "";	
							}else{
								idAppend = "_" + id;
							}
							if(html.length == 0){	
								housing_label = $('label[for="festival_housing' + idAppend + '"]');
								housing_label.html('Festival Housing');
								$("#festival_housing_drop_down" + idAppend).html(html).slideUp();
							}else{
								housing_label = $('label[for="festival_housing' + idAppend + '"]');
								housing_label.html('Festival Housing (If Not Listed Above)');
								$("#festival_housing_drop_down" + idAppend).html(html).slideDown();
							}
					   }
					 });	
				}
			}
		});
	});
	
	$('.email_contact_before').live('keyup',function(){
		id = $(this).attr('id');
		ids = id.split("_");
		id = ids[4];
		$('#email_contact_at_fot_' + id).val($(this).val());
	});
	
	$('.phone_contact_before').live('keyup',function(){
		id = $(this).attr('id');
		ids = id.split("_");
		id = ids[4];
		$('#phone_contact_at_fot_' + id).val($(this).val());
	});
	
	$('.email_contact_at').live('keyup',function(){
		id = $(this).attr('id');
		ids = id.split("_");
		id = ids[4];
		$('#email_contact_before_fot_' + id).unbind().removeClass('email_contact_before');
	});
	
	$('.phone_contact_at').live('keyup',function(){
		id = $(this).attr('id');
		ids = id.split("_");
		id = ids[4];
		$('#phone_contact_before_fot_' + id).unbind().removeClass('phone_contact_before');
	});

});

function confirmDelete() {
  
  var agree = confirm('Delete this record?');
  
  if (agree == true) { return true; } else { return false; }

}

/*****************/		

/*****************/
