﻿function initSlider()
{
    //Set Default State of each portfolio piece
    $(".paging").show();
    $(".paging a:first").addClass("active");

    //Get size of images, how many there are, then determin the size of the image reel.
    var imageWidth = $(".window").width();
    var imageSum = $(".image_reel img").size();
    var imageReelWidth = imageWidth * imageSum;
 
    //Adjust the image reel to its new size
    $(".image_reel").css({'width' : imageReelWidth});

    //Paging + Slider Function

    rotate = function(anim){    

        var triggerID = $active.attr("rel") - 1; //Get number of times to slide

        var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

        $(".paging a").removeClass('active'); //Remove all active class

        $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

        //Slider Animation
		
        $(".image_reel").animate({ 

            left: -image_reelPosition

        }, (anim?750:0) );
    }; 

    //Rotation + Timing Event

    rotateSwitch = function(){      

        play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds

            $active = $('.paging a.active').next();

            if ( $active.length === 0) { //If paging reaches the end...

                $active = $('.paging a:first'); //go back to first
				rotate(false);
            }
			else rotate(true); //Trigger the paging and slider function

        }, 9000); //Timer speed in milliseconds (3 seconds)

    };

    rotateSwitch(); //Run function on launch

    //On Hover
    $(".image_reel a").hover(function() {

        clearInterval(play); //Stop the rotation

    }, function() {

        rotateSwitch(); //Resume rotation

    }); 

    //On Click

    $(".paging a").click(function() {   

        $active = $(this); //Activate the clicked paging

        //Reset Timer

        clearInterval(play); //Stop the rotation

        rotate(false); //Trigger rotation immediately

        rotateSwitch(); // Resume rotation

        return false; //Prevent browser jump to link anchor

    }); 
}

function setSize() {
	var w = 0;

	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	w=window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	w=document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	w=document.body.clientWidth;
	}
	if(w>=1350) w=1350;

	document.getElementById("tbl_main").width = "" + parseInt((w/1.2<905?905:w/1.2));
}

function validateForm() {
	var req_fields = new Array("visitor_name","visitor_email_address","visitor_phone_number","visitor_home_address","visitor_city_state","visitor_zip_code","visitor_stay_length","visitor_arrival_day");
	var ob;
	var submit = true;
	
	for(var i=0;i<req_fields.length;i++)
	{
		if(document.getElementById(req_fields[i]).value=="")
		{
			if((ob=document.getElementById("req_" + req_fields[i]))!=null) ob.style.display = 'inline';
			else {
				ob = document.getElementById(req_fields[i]).parentNode;
				ob.innerHTML += '<br/><span id="req_' + req_fields[i] + '" class="frm_req">* Required field. Please specify.</span>';
			}
			submit = false;	
		}
		else if((ob=document.getElementById("req_" + req_fields[i]))!=null) ob.style.display = 'none';
	}
	
	if(!echeck(document.getElementById("visitor_email_address").value)) 
	{
		if((ob=document.getElementById("req_" + req_fields[1]))!=null) 
		{
			ob.innerHTML = "* Please specify a valid e-mail address.";
			ob.style.display = 'inline';
		}
		else
		{
			ob = document.getElementById(req_fields[1]).parentNode;
			ob.innerHTML += '<br/><span id="req_' + req_fields[1] + '" class="frm_req">* Please specify a valid e-mail address.</span>';
		}
		submit = false;
	}
	else if((ob=document.getElementById("req_" + req_fields[1]))!=null) ob.style.display = 'none';
	
	if(submit) document.getElementById("submit").click();
}

function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		 
		 var invalidchars = " /;:()<>[]"
		 
		 for(var i=0;i<invalidchars.length;i++)
		 {
		 	if(str.indexOf(invalidchars.substr(i,1))!=-1)
		 	{
		 		return false;
		 	}
		 }
				 
		 if (lstr>255){
		 	return false;
		 }

 		 return true;					
}

function resetForm()
{
	var req_fields = new Array("visitor_name","visitor_email_address","visitor_phone_number","visitor_home_address","visitor_city_state","visitor_zip_code","visitor_stay_length","visitor_arrival_day");
	
	for(var i=0;i<req_fields.length;i++)
	{
		if((ob=document.getElementById("req_" + req_fields[i]))!=null) ob.style.display = 'none';
	}
}

function checkOther(select)
{
	var input = document.getElementById("found_us_other");
	if (select.value.substr(0,5)=="Other")
	{
		input.disabled = false;
		input.focus();	
	}
	else
	{
		input.value = '';
		inpud.disabled = true;
	}
}
