

/*************************  HIGHLIGHTING CURRENT PAGE  **************************/
$(document).ready(function() {


			/**********************************************************************************************/
			
			/*   ATTENTION, FOR THIS SCRIPT TO WORK YOU MUST SET THE HREF WITHIN THE LINK TO A FULL URL    */
			/*   FOR INSTANCE http://mydomain.com/page1.html AS OPPOSED TO  page1.html                     */
		//set the ID of the menu
			
				//current location
			var href = jQuery(location).attr('href');
	/*	
		//REPEAT THE SCRIPT BELOW IF YOU WANT THIS TO WORK ON SEVERAL MENUS
		$('#top_nav li a').each(function(index) {
   				
						if ($(this).attr('href')== href)
						{
									$(this).addClass('top_nav_on');
									$(this).parent().addClass('top_nav_li_on');
						}//end if
							
	  			});//end loop
		
		*///e8d2a2  
		
					$("#main_nav li .dropdown").hover(
										
  function () { $(this).prev().css('background', '#e8d2a2');$(this).prev().css('color', '#764c0e');}, 
 function () {$(this).prev().css('background', '');$(this).prev().css('color', ''); }

  
  /* works by adding the class
  function () { $(this).prev().addClass('link_hover');}, 
  function () {$(this).prev().css('background', '');$(this).prev().css('color', '#e8d2a2'); }
  */
  
    
	);
	


//see if we show the little ads or not
	var windH = $(window).height();
	var usedH = parseInt($('.inside_left_menu').height()) + 220 + 100;//adding the margin loeft for the left menu and 100 extra for the ad box
	
		if (usedH > windH){$('#side_ads').hide();}


				
});


function openHomeAd()
{
	$('#offer_box').show();
	$('#offer_box').animate({
    opacity: 1,
	left: '50%',
    height: '220px',
	width: '250px',
	bottom: '208px',
	marginLeft: '-479px'
  }, 300, function() {
    // Animation complete.
  });
	
}//end function 



	$(window).load(function(){
							
			var index = 0;//all pages
			//home page, no add below
			if (String(jQuery(location).attr('href'))=='http://www.killeencastle.com/index.asp' || String(jQuery(location).attr('href'))=='http://www.killeencastle.com/')
			{index = 1;
			}
			
			
	if (index==1)
	{
		
		window.setTimeout('showContent(1)',8000);
		//window.setTimeout('openHomeAd()',8000);
		openHomeAd();
		
	}
	else
	{
		if (jQuery(location).attr('href')!='http://www.killeencastle.com/golf-club/hole-by-hole.asp')//don't show hole by hole
		{
		showContent(0)
		}
	}


	});
	


//open and close the content
var contO = 0;

	function showContent(page)
	{
			
		
		//open or close
		if (contO==0)
		{//open
			
			//calculate how height we are going
			var newHeight = 350;//-550 instead of -50, so 500 in the difference
			
			if (page==0)
			{
				newHeight = newHeight + 250;
				
			}
			
			
			//$('#calc').append('<br>newHeight:'+newHeight )
			//now calcualte the maximum height it can go to
			var wind = parseInt($(window).height());
			//$('#calc').append('<br>doc height:'+$(document).height() )
				//remove the footer space, the header, the height of the box and an extra margin
				var extraMargin = -50;
				var footer = 291;//for the home page
				if (page==0)
			{
				footer = 170;
				
			}
				//alert('footer: ' + footer)
				
				var wind = wind - (footer + 96 + 41 + extraMargin);
				//$('#calc').append('<br>extra margin:'+extraMargin )
				//if the new top is higher we have to reduce it accordingly
				if (newHeight > wind){newHeight = wind;
				//move up the left menu
				$('#inside_left_col').css('top','195px')
				
				}
				
				//alert('document height: ' + $(window).height() + ' new height: ' +newHeight + ' window is ' + wind)
				$('#content_text').css('height',''+newHeight+'px')
				

			$('#content_text').slideDown(600);
			
			//change the button
			$('#content_button').html('<a href="javascript:showContent('+page+')" class="link_close">Close</a>');
			
			
			
			//alert('');
			contO = 1;
			
		}
		else
		{//close
				
			$('#content_text').slideUp(600);
			
			//change the button
			$('#content_button').html('<a href="javascript:showContent('+page+')" class="link_open">Open</a>');
			
			
			
			contO = 0;
			
		}
		
		
		
		
	}
















var fScreen = 0;

		function fullScreen()
		{
			if (fScreen==0)
			{
				
					$('#header').slideUp();
					$('#cta_boxes').slideUp();
					$('#content_text').fadeOut();
					$('#text_box_open').fadeOut();
					$('#inside_left_col').fadeOut();
					$('#offer_box').fadeOut();
					$('#full_screen').html('<img src="http://www.killeencastle.com/library/slide_controls/contract.png" width="20" height="21" alt="Normal view" />')
				
				fScreen = 1;
			}
			else
			{
				$('#header').slideDown();
				$('#cta_boxes').slideDown();
				$('#content_text').fadeIn();
					$('#text_box_open').fadeIn();
					$('#inside_left_col').fadeIn();
					$('#offer_box').fadeIn();
				$('#full_screen').html('<img src="http://www.killeencastle.com/library/slide_controls/enlarge.png" width="20" height="21" alt="Full screen view" />')
				fScreen = 0;	
			}
			
			
		}//end function


/********** Scrollbar **********/

$(window).load(function() {

	//mCustomScrollbars();
});
/*
function mCustomScrollbars(){
	/* 
	malihu custom scrollbar function parameters: 
	1) scroll type (values: "vertical" or "horizontal")
	2) scroll easing amount (0 for no easing) 
	3) scroll easing type 
	4) extra bottom scrolling space for vertical scroll type only (minimum value: 1)
	5) scrollbar height/width adjustment (values: "auto" or "fixed")
	6) mouse-wheel support (values: "yes" or "no")
	7) scrolling via buttons support (values: "yes" or "no")
	8) buttons scrolling speed (values: 1-20, 1 being the slowest)
	*/
	/*
	$("#content_text").mCustomScrollbar("vertical",300,"easeOutCirc",1.05,"auto","yes","yes",15); 
	
}
*/
/* function to fix the -10000 pixel limit of jquery.animate */
$.fx.prototype.cur = function(){
    if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
      return this.elem[ this.prop ];
    }
    var r = parseFloat( jQuery.css( this.elem, this.prop ) );
    return typeof r == 'undefined' ? 0 : r;
}

/* function to load new content dynamically */
function LoadNewContent(id,file){
	$("#"+id+" .customScrollBox .content").load(file,function(){
		mCustomScrollbars();
	});
}


function buyVoucher(id,prod_name)
{
	//vouchers going to paypal (temporary)
			
			//get the price
			var price = $('#voucher_choice_'+id).val();
			
			
			var url = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=info@killeencastle.com&item_name=Voucher purchase: "+prod_name+" (Euro "+price+")&currency_code=EUR&amount="+price+"&item_number="+id+"";
			
			document.location = url;
	
}//end of function 


var newLopen = 0;

		function openNewsL()
		{
		
				if (newLopen==0)
				{
					$('#newsletter_signup_layer').slideDown();
					
					
					newLopen = 1;
				}
				else
				{
					$('#newsletter_signup_layer').slideUp();
					newLopen=0;	
				}
		
		}
		
	

emai = /^\w+([\.'-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	function registerNewsL()
	{
		var error = '';
		
		if (document.newsl.cust_title.value==""){
                error = error + "\nPlease select a title";
        }
		
		if (document.newsl.cust_fname.value==""){
                error = error + "\nPlease enter a first name";
        }
		
		if (document.newsl.cust_lname.value==""){
                 error = error + "\nPlease enter a last name";
        }
		
	
	if (!emai.test(document.newsl.cust_email.value)){
	 error = error + "\nPlease enter a valid email address";
        }
		
		if (document.newsl.countryId.value==""){
                error = error + "\nPlease select a country";
        }
		
		if (error!='')
		{
			
			alert("The following error(s) occured, please correct and submit again:" + error)
			
		}
		else
		{
		
							$.ajax({
				
						type: "POST",
						url: "http://www.killeencastle.com/ssi/newletter_reg2.asp",
						data: {cust_title: document.newsl.cust_title.value,cust_fname: document.newsl.cust_fname.value,cust_lname: document.newsl.cust_lname.value,cust_email:document.newsl.cust_email.value,countryId:document.newsl.countryId.value},
						success: function(dataBack){
												
												if(dataBack==1)
												{
													
												$('#newsletter_signup_layer').html('<h3>Newsletter Signup</h3><p>In order to verify your email address an email has been sent to '+document.newsl.cust_email.value+'</p><p>Please check your inbox and click on the link sent to finalise your subscription</p><p><a href="javascript:openNewsL()" class="close_button">Close</a></p>');	
													
												}
												else
												if(dataBack==1)
												{
													
												$('#newsletter_signup_layer').html('<h3>Newsletter Signup</h3><p>Sorry, it appears you are already registered for our newsletter.</p><p><a href="javascript:openNewsL()" class="close_button">Close</a></p>');	
													
												}
												else
												if(dataBack==-1)
												{
													
												$('#newsletter_signup_layer').html('<h3>Newsletter Signup</h3><p>Sorry, the referrer was not recognized and your subscription not possible.</p><p><a href="javascript:openNewsL()" class="close_button">Close</a></p>');	
													
												}
											},
											error: function(x,e){
																if(x.status==0){
																alert('You are offline!!\n Please Check Your Network.');
																}else if(x.status==404){
																alert('Requested URL not found.');
																}else if(x.status==500){
																alert('Internel Server Error.');
																}else if(e=='parsererror'){
																alert('Error.\nParsing JSON Request failed.');
																}else if(e=='timeout'){
																alert('Request Time out.');
																}else {
																alert('Unknow Error.\n'+x.responseText);
																}
															}
				
				
				
				
				});
			
			
			
			
		}//end of no error
		
		
		//return false;//block the form
		
		
	}//end function


