$(document).ready( function()
{
	$(".vidbox").jqvideobox();
	
	$("#ranch_state").change( function()
	{	
		$("#loadShowCounty").css("visibility", "visible");
		$("#primaryCounties").css("visibility", "hidden");
		var stateId = $("#ranch_state").val();
		
		$.ajax({
				type: "POST",
				url: "http://www.ranchworld.com/dropdown-county.php",
				data: "postStateVal="+stateId,
				success: function( returndata )
				{
					$("#loadShowCounty").css("visibility", "hidden");
					$("#showCounty" ).html(returndata);
				}
		});
		
	});
	
	
	$("#ValidField").validate({
		expression: "if (VAL) return true; else return false;",
		message: "Please enter the Required field"
	});
	$("#Email").validate({
		expression: "if (VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;",
		message: "Should be a valid Email id."
	});
	$("#Phone").validate({
		expression: "if (!isNaN(VAL) && VAL) return true; else return false;",
		message: "Should be a valid Phone Number."
	});
	
	//Start Main Gallery
    var galleries = $('.ad-gallery').adGallery();
    $('#switch-effect').change(
      function() {
        galleries[0].settings.effect = $(this).val();
        return false;
      }
    );
    $('#toggle-slideshow').click(
      function() {
        galleries[0].slideshow.toggle();
        return false;
      }
    );
    $('#toggle-description').click(
      function() {
        if(!galleries[0].settings.description_wrapper) {
          galleries[0].settings.description_wrapper = $('#descriptions');
        } else {
          galleries[0].settings.description_wrapper = false;
        }
        return false;
      }
    );
	//End Main Gallery
	
	$("a[rel='example1']").colorbox();
	
	$("a[rel='ranch_details_colorbox']").colorbox();
	
	$(".colorbox_video").colorbox();
	
	$("#clickme").click(function(){
		$("#openRegForm").toggle();
	});
	
	//Examples of how to assign the ColorBox event to elements
	$("a[rel='example1']").colorbox();
	$("#click").click(function(){ 
		$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
		return false;
	});
	
	$("ul.prettyGallery").prettyGallery({
			itemsPerPage : 5,
			animationSpeed : 'slow', /* fast/normal/slow */
			navigation : 'top',  /* top/bottom/both */
			of_label: ' of ', /* The content in the page "1 of 2" */
			previous_title_label: 'Previous page', /* The title of the previous link */
			next_title_label: 'Next page', /* The title of the next link */
			previous_label: 'Previous', /* The content of the previous link */
			next_label: 'Next' /* The content of the next link */
	});
		
});


function exitpop()
{	
	try{
		frmObj        = jQuery('#frmprint');
		targetWinName = "mywindow1";
		myWindow      = window.open("", targetWinName, "status=1,width=800,height=900,scrollbars=yes");
		frmObj.target = targetWinName;
    	frmObj.submit();
		myWindow.focus();
		return false;
	}catch(err){}
}


function showSignupPageFlip()
{
	$(document).ready(function(){
	//Page Flip on hover
		$("#pageflip").hover(function() {
			$("#pageflip img , .msg_block").stop()
				.animate({
					width: '307px', 
					height: '319px'
				}, 500); 
			} , function() {
			$("#pageflip img").stop() 
				.animate({
					width: '50px', 
					height: '52px'
				}, 220);
			$(".msg_block").stop() 
				.animate({
					width: '50px', 
					height: '50px'
				}, 200);
		});
	});
}


$(function(){
	//Get our elements for faster access and set overlay width
	var div = $('div.sc_menu'),
		ul = $('ul.sc_menu'),
		ulPadding = 15;
	
	//Get menu width
	var divWidth = div.width();

	//Remove scrollbars	
	div.css({overflow: 'hidden'});
	
	//Find last image container
	var lastLi = ul.find('li:last-child');
	
	//When user move mouse over menu
	div.mousemove(function(e){
		//As images are loaded ul width increases,
		//so we recalculate it each time
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});


function clearText(field)
{
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}

