var navivals=new Array("75px","153px","240px","342px","437px");
//var selindex=0;
var rolledover=selindex;

$(document).ready(function(){
						   
	
	//INPUT CLEAR
	
	//clear form inputs (add & uses rel attributes for comparison)
	$('.inputClear').focus(function(){
		if(!$(this).attr('rel')) {
			$(this).attr('rel',$(this).val()).val('');
		} else {
			if($(this).val()==$(this).attr('rel')) $(this).val('');
		}
	}).blur(function(){
	   if($(this).val()=="") $(this).val($(this).attr('rel'));
	});
	
	//CHKEML

(function(a){a.fn.checkEmail=function(){var b;this.each(function(){var c=a(this).val();b=c.indexOf("@")==-1||c.lastIndexOf(".")==-1?false:true});return b}})(jQuery);

						   
	//LIFE SUPPORT FORM


    $('#life_s').submit(function(){
        
        chkeml = $('#ls_email').checkEmail();
        var email=$('#ls_email').val();
        var comments=$('#ls_comments').val();
    
    if(chkeml)
    {

        $.ajax({
                type: "POST",
                url: 'scripts/php/enquiry.php',
                data: "email="+email+"&comments="+comments,
                success: function(data){
                    
                    $('#ls_feedback').html(data).slideDown('slow').delay('4000').slideUp();
                                   
                }               

            });
            
    }
    else
    {       
            $('#ls_feedback').html('Please enter a valid email address').slideDown('slow').delay('4000').slideUp();       
    }
    return false;
});	
	
	//FREE DAY PASS FORM


    $('#f_pass').submit(function(){
        
		
		var firstname = $('#fp_fname').val();
		var surname = $('#fp_sname').val();
		var contactnumber = $('#fp_contactnumber').val();
        chkeml = $('#fp_email').checkEmail();
        var email = $('#fp_email').val();
        var hearabout = $('#fp_hear').val();
		
    
    if(chkeml)
    {

        $.ajax({
                type: "POST",
                url: 'scripts/php/daypass.php',
                data: "firstname="+firstname+"&surname="+surname+"&contactnumber="+contactnumber+"&email="+email+"&hearabout="+hearabout,
                success: function(data){
                    
                    $('#fp_feedback').html(data).slideDown('slow').delay('4000').slideUp();
                                   
                }               

            });
            
    }
    else
    {       
            $('#fp_feedback').html('Please enter a valid email address').slideDown('slow').delay('4000').slideUp();       
    }
    return false;
});	
						   

	$('#lightboxbutton').fancybox();
	
	$("#daypass").submit(function(){
		error = 0;
		$(".required").each(function(){
			currentVal = $(this).val();
			if(currentVal == ""){
				error = 1;
			} 
		});
		
		if(error == 1){
			$("#dp_feedback").html("Please ensure all fields are filled in.");	
		} else {
			expVals = "";
			$(".used").each(function(){
				expVals=expVals+$(this).val()+"{spl}";
			 });
			$.ajax({ 
			type: "POST", 
			url: "/scripts/php/daypass.php", 
			data: "func=submited&vals="+expVals, 
			success: function(data){
				$("#dp_feedback").html(data);
			}
		});

		}
			
		return false;
								  
	});
	

	$(window).bind("load",function(){
		
		$('#hw_images img').css("display","block");
		
		$('#hw_images').cycle({
			speed:800,
			timeout:6000
		});
		
		$('#hw_txt').cycle({
			speed:800,
			timeout:6000
		});
		
		$('#headnacv1 li a').mouseover(function(){
			if($('#headnacv1 li a').index(this)!=rolledover)
			{
				rolledover=$('#headnacv1 li a').index(this);
				NaviGateTo($('#headnacv1 li a').index(this));
			}
		});
		
		$('.headsubnavi').eq(0).customFadeIn(400);
		
		$('.specialoffer_con').fadeTo(100, 0.7,function(){
			ClearTypeFix(this);											
		});	
	});
	
	$('.classinfo').css("left","-700px").eq(0).css("left","0px");
	
	
	$('.class_button li').click(function(){
		thisindex=$('.class_button li').index(this)+1;

		if($('.classinfo').eq(thisindex).css("left")=="0px")
		{
			$('.classinfo').eq(thisindex).MyAnimate("-700px");
		}
		else
		{
			$('.classinfo').MyAnimate("-700px");
			$('.classinfo').eq(0).MyAnimate("0px");
			$('.classinfo').eq(thisindex).MyAnimate("0px");
		}	
	});
	
	
	
	$('.class_button li').mouseover(function(){
		$(this).css("backgroundPosition","left bottom");										 
	});
	
	$('.class_button li').mouseout(function(){
		$(this).css("backgroundPosition","left top");										 
	});
	
	$('#nav_arrow').css("left",navivals[0]);	
	
	$('#headnacv1 li a').eq(selindex).css({
		color: "#5EA6D0",
		"font-size": "1.0em"
	});

	$('#hw_images img').each(function(i){
		if(i>0)
		{
			$(this).css("display","none");	
		}
	});
	
});

function ClearTypeFix(selelement)
{
	if(jQuery.browser.msie)
	{
		$(selelement).get(0).style.removeAttribute('filter');
	}
}

(function($) {	
	$.fn.MyAnimate = function(moveleft, callback){
		$(this).animate({
			"left":	moveleft	
		},{ duration: 600, queue: false, "easing":"swing"});
	};
	  
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

function NaviGateTo(aniindex)
{
	$('.headsubnavi').customFadeOut(400);
	
	$('#nav_arrow').stop().animate({
	left: navivals[aniindex]					
	},300, "swing",function(){
			$('.headsubnavi').eq(rolledover).customFadeIn(400);
		});		
}

//OFFER CYCLE

if($('#offers').length>0){
	$('#offers') 
		.after('<div id="offers_nav" class="scroll_controls scroll_multi">') 
		.cycle({ 
			fx:     'scrollLeft', 
			speed:  'slow', 
			pager:  '#offers_nav' 
	});
}

//NEWS CYCLE

$('#news').cycle({ 
    fx:     'scrollLeft', 
    speed:  'slow',
    timeout: 0,  
    next:   '#n_next', 
    prev:   '#n_prev' 
});



//ACCORDION CALL
	if($('div.faq').length>0){
		$('div.faq').accordion({
			collapse: true
		});
	}

/* ============================================================
 * bootstrap-dropdown.js v1.4.0
 * http://twitter.github.com/bootstrap/javascript.html#dropdown
 * ============================================================
 * Copyright 2011 Twitter, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============================================================ */


!function( $ ){

  "use strict"

  /* DROPDOWN PLUGIN DEFINITION
   * ========================== */

  $.fn.dropdown = function ( selector ) {
    return this.each(function () {
      $(this).delegate(selector || d, 'click', function (e) {
        var li = $(this).parent('li')
          , isActive = li.hasClass('open')

        clearMenus()
        !isActive && li.toggleClass('open')
        return false
      })
    })
  }

  /* APPLY TO STANDARD DROPDOWN ELEMENTS
   * =================================== */

  var d = 'a.menu, .dropdown-toggle'

  function clearMenus() {
    $(d).parent('li').removeClass('open')
  }

  $(function () {
    $('html').bind("click", clearMenus)
    $('body').dropdown( '[data-dropdown] a.menu, [data-dropdown] .dropdown-toggle' )
  })

}( window.jQuery || window.ender );

 


