jQuery(document).ready(function(){

	// jQuery Scroller
	/*
	$('#scroller').easySlider({
		continuous: true,
		prevId: 'scroll-prev',
		nextId: 'scroll-next'
	});
	*/
	
	// Fancybox lightbox elements
	
	//$('a.lightbox').fancybox();
	
	//$('a.portfolio-mag').fancybox();
	
	//$('a.scroll-mag').fancybox();
	/*
	$('.scroll-mag').stop().css({
		'opacity': 0
	});
	*/
	// Custom magnify icon fades
	/*
	$('a.lightbox').hover(function(){
		$('.scroll-mag').stop().animate({
			'opacity': 1
		}, 700);
	}, function(){
		$('.scroll-mag').stop().animate({
			'opacity': 0
		}, 700);
	});
	
	$('a.scroll-mag').hover(function(){
		$('.scroll-mag').stop().animate({
			'opacity': 1
		}, 700);
	}, function(){
		$('.scroll-mag').stop().animate({
			'opacity': 0
		}, 700);
	});
	*/
	// Input Fields
/*
	jQuery('input, textarea').each(function () {
		if (jQuery(this).val() == '') {
			jQuery(this).val($(this).attr('name'));
		}
	}).focus(function () {
		jQuery(this).removeClass('inputerror');
		if (jQuery(this).val() == jQuery(this).attr('name')) {
			jQuery(this).val('');
		}
	}).blur(function () {
		if (jQuery(this).val() == '') {
			jQuery(this).val(jQuery(this).attr('name'));
		}
	});
	*/
	//scroll the message box to the top offset of browser's scrool bar
	//$(window).scroll(function()
	//{
	  //jQuery('#message_box').animate({top:$(window).scrollTop()+"px" },{queue: false, duration: 350});
	//});
	//when the close button at right corner of the message box is clicked
	//jQuery('#close_message').click(function()
	//{
	  //the messagebox gets scrool down with top property and gets hidden with zero opacity
	  //jQuery('#message_box').animate({ top:"+=15px",opacity:0 }, "slow");
	//});

	jQuery('#featured-parcel-messages').innerfade({
					animationtype: 'fade',
					speed: 'slow',
					timeout: 6000,
					type: 'sequence',
					containerheight: '20px'
				});

if (!browserLessThanIE7()) {
		 jQuery("#showcaseInfo").jCarouselLite({
	    btnNext: ".next",
	    btnPrev: ".prev",
		auto: 7000,
		 
		 speed:800,
		 visible:1,
		 vertical:true
	   });

		 jQuery("#showcaseImages").jCarouselLite({
	    btnNext: ".next",
	    btnPrev: ".prev",
		auto: 7000,
		 
		 speed:800,
		 visible:1
	   });

		 jQuery('#showcaseNav a').fadeTo("fast",0.50);
		 jQuery('#showcaseNav a').hover(function() {
			jQuery(this).fadeTo("fast",1);
			},
			function () {
	       jQuery(this).fadeTo("fast",0.50);
	     });
	
} else {
	 jQuery("#showcaseInfo ul li:gt(0)").hide();
	 jQuery("#showcaseImages ul li:gt(0)").hide();	
	 jQuery("#showcaseNav").hide();
}

			// initialize scrollable 
				jQuery("div.scrollable").scrollable({
					vertical:true, 
					size: 2,
					loop:true
				}).autoscroll({ 
					autoplay: true, 
					autopause: true,
					interval: 3000
				});
				
				// initialize tooltip
				/*
				jQuery("a[title]").tooltip({

					// use single tooltip element for all tips
					tip: '#dynatip', 
					
					// tweak the position
					//offset: [10, 2],

					// use "slide" effect
					effect: 'slide',
					// another property 
					    opacity: 0.7,
						events: { 
							    def:      "mouseover,mouseout", 
						        input: 'click, blur', 
						        checkbox: 'mouseover click, mouseout', 
						        date: 'click, blur' 
						    }
				});.dynamic( {

								// customized configuration on bottom edge
								bottom: {

									// slide downwards
									direction: 'down',

									// bounce back when closed
									bounce: true
								}
							});
					*/
		
				//	$('body#home #body').slideToggle();					
/*					
	//checkout tweaks
	//when the checkbox is checked or unchecked
    $('#shippingSameBilling2').click(function() {

        // If checked
        if ($("#shippingSameBilling").is(":checked")) {
			
			$(".first-name:eq(1)").val($(".first-name:eq(0)"));
			
			$("#wpsc_checkout_form_10").val($("#wpsc_checkout_form_2").val());
			$("#wpsc_checkout_form_11").val($("#wpsc_checkout_form_3").val());
			$("#wpsc_checkout_form_12").val($("#wpsc_checkout_form_4").val());
			$("#wpsc_checkout_form_13").val($("#wpsc_checkout_form_5").val());

//			$("#wpsc_checkout_form_14").val($("#wpsc_checkout_form_6").val());

			$("#wpsc_checkout_form_16").val($("#wpsc_checkout_form_7").val()); //postal code
			$("#wpsc_checkout_form_14").val($(".current_region:eq(0)").val());
			
            //won't work on drop downs, so get those values
            //var bcountry = $("#wpsc_checkout_form_6").val();
            //$("#scountry").selectOptions(bcountry);                    

        } else {
			$(".first-name:eq(1)").val("");

			$("#wpsc_checkout_form_10").val("");
			$("#wpsc_checkout_form_11").val("");
			$("#wpsc_checkout_form_12").val("");
			$("#wpsc_checkout_form_13").val("");

			$("#wpsc_checkout_form_16").val(""); //postal code
			$("#wpsc_checkout_form_14").val("");
       }
    });
*/
	//clean up shipping calc area on checkout
	$("table.shipping-details tr:eq(2)").hide();
	$("table.shipping-details tr:eq(3)").hide();
	
	$("#flatrate_1").attr("checked", "checked");
	$("#flatrate_1").parent().hide();
	
    //make deluxe package description links popup windows
	$(".wpsc_description a").addClass("popupWindow");

	$('.popupWindow').popupWindow({ 
	centerBrowser:1,
	resizable:1,
	scrollbars:1
	});

	$("#formwrap fieldset:eq(1) label:eq(1)").hide();
	$("#formwrap fieldset:eq(1) input:eq(1)").hide();

	var bodyId = $("body").attr("id");

	if (bodyId=="map")
		if (browserLessThanIE7()) {
			alert('This site is best experienced in IE7 and higher. Please ensure your browser security settings allow ActiveX controls under Tools > Options > Security Tab. Otherwise please try Firefox, Chrome or Safari.');
			//humanMsg.displayMsg('This site is best experienced in IE7 and higher. Please ensure your browser security settings allow ActiveX controls under Tools > Options > Security Tab. Otherwise please try Firefox, Chrome or Safari.');
		}
	
	jQuery("#goto-faq").click(function () {
		var targetOffset = $("#faq-anchor").offset().top;
		$('html,body').animate({scrollTop: targetOffset}, 500);
	});

	if (bodyId=="home")
		jQuery("#header").slideDown();
		
	if (bodyId=="contact")
		$("#phone").val("n/a");
	
	if (bodyId=="checkout" && $(".validation-error")) { //if there were any validation errors then scroll down to them automatically 

		var targetOffset = $("#faq-anchor").offset().top;
		$('html,body').animate({scrollTop: targetOffset}, 500);
		
	}
	//clone the select this package buttons
	if (bodyId=="products-page") {
		$("#buy-button-1").clone(true).insertAfter("#prod-title-1");
		$("#buy-button-2").clone(true).insertAfter("#prod-title-2");
	}
});

function scrollWin(){
	$('html, body').animate({
	scrollTop: $("#body").offset().top
	}, 2000);
}

function generateDocuments(ParcelID,SessionID) {
	
	var path = 'http://'+ document.domain +'/wp-content/themes/oceansforme/';
	
	
	
	if (ParcelID=="" && SessionID=="") { 
		$("#header").toggle();
		$("#body").toggle();
	//	alert("There was a problem with your parcel documents. Please contact us through the contact form.");
		//$(location).attr('href','/contact/');
		$('#basic-modal-content').html('<h3>We are sorry about this...</h3> <br><h4>We had a problem generating your documents.  Please contact customer support and mention '+ParcelID+'-'+SessionID+'.</h4><br><br><center><img src="/wp-content/themes/oceansforme/images/ajax-loader-1.gif" align="center"></center>');
		
		$('#basic-modal-content').modal({overlayClose:false, 
			opacity:70,
				overlayCss: {backgroundColor:"#fff"}
		});
		return;
	}
	
	$('#basic-modal-content').modal({overlayClose:false, 
		opacity:70,
			overlayCss: {backgroundColor:"#fff"}
	});
	
	$.ajax({
	type: 'GET',
	url: path+'generatedocs.php',
	data: 'ParcelID='+ParcelID+"&SessionID="+SessionID,
	dataType: 'html',
	async: true,
	cache: false,
	success: function(a){
		//var a = JSON.parse(a);
		//$("#waitingMessage").css('display','none');
		mylog(a);
		$('#parcel-doc-links').css('display','');
		$('#parcel-view-link').css('display','');
		
		links = a.split(',');
		
		if (links[0] && links[1] && links[2]) {
			

		mylog(links);
		certificate = links[0].replace('+','%20');
		letter = links[1].replace('+','%20');
		map = links[2].replace('+','%20');
		
		$("#certificate_download").attr("href","/docredir.php?url="+certificate);
		$("#letter_download").attr("href","/docredir.php?url="+letter);
		$("#map_download").attr("href","/docredir.php?url="+map);
		
		$("#certificate_view").attr("href",certificate);
		$("#letter_view").attr("href",letter);
		$("#map_view").attr("href",map);
		
		//tiltCamera(0);

		$.modal.close();
		} else {
			$('#main').toggle();
			$('#basic-modal-content').html('<h3>We are sorry about this...</h3> <br><h4>We had a problem generating your documents.  Please contact customer support and mention '+ParcelID+'-'+SessionID+'.</h4><br><br>');

			$('#basic-modal-content').modal({overlayClose:false, 
				opacity:70,
					overlayCss: {backgroundColor:"#fff"}
			});
			return
		}
	},
	error: function(msg){
		//var search = ID;
		//mylog(msg);
		//alert('Error:'+msg);
		//runGeoCode(currentSearch);

		$.modal.close();
		
	}
	});

}
function browserIsIE7(){
   return (/MSIE (7)/.test(navigator.userAgent) && navigator.platform == "Win32");
}

function browserLessThanIE7(){
   return (/MSIE ((5\\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
}

function openPopup(url){
  	var windowFeatures =    'height=400,width=400,toolbar=0,scrollbars=1,status=0,resizable=1,location=0,menuBar=0';
  	window.open(url, '', windowFeatures).focus();
}




function mylog(message) {
  if(window.console) {
     //console.debug(message);
  } else {
     //alert(message);
  }

}