$(function () {

	$('.page_item a').parent().hover(function(){
		$(this).addClass('current_page_item').addClass('drop');
		$('ul.children',this).show();
	},function(){
		$(this).removeClass('current_page_item').removeClass('drop');
		$('ul.children',this).hide();
	});
	
	if($("#mcs_container").length > 0){
		loadScrollbars();
	}
	
	if($('#sticky-anchor').length > 0){
		function sticky_relocate() {
			var window_top = $(window).scrollTop();
			var offset = $('#sticky-anchor').offset();
			var div_top = offset.top;
			if (window_top > div_top){
				$('#sticky').addClass('stick');
			}else{
				$('#sticky').removeClass('stick');
			}
		}
		$(window).load(sticky_relocate);
		$(window).scroll(sticky_relocate);	
	}
	
	if($('#contact-form').length > 0){
		
		$('p.warning').remove();
		$('div.thanks').hide();
		$('p#send_to').hide();
		$.ajax({
			type: "POST",
			url: app.baseurl+'scripts/ajax/token.php',
			success: function(txt){
				$('fieldset#ghost').append('<input type="hidden" name="ts" value="'+txt+'" />');
			}
		});
		$("#contact-form").validate({
			rules: {
				name: "required",
				email:  {
					required: true,
					email: true
				},
				phone: "required",
				comments: "required"
			},
			errorElement : "span",
			errorPlacement : function(error,element){
				error.appendTo(element.prev())
			},
			messages: {
				name: "Required",
				email: "Valid Email Required",
				phone: "Required",
				comments: "Required",
			},
			submitHandler: function(form){
				$(form).ajaxSubmit({
					success: function(){
						$('#contact-form').slideUp('fast');
						$('div.thanks').slideDown('fast');
					}
				});
			}
		});
		
	}
	
});

var loc = new String(window.parent.document.location);
if (loc.indexOf("https://")!= -1)
prefix = "https://";
else
prefix = "http://";

var app = {
    rate: 200,
    baseurl: prefix +window.location.hostname+'/wp-content/themes/bioeden2011/'
};

function loadScrollbars(){
	$("#mcs_container").mCustomScrollbar("vertical",app.rate,"easeOutCirc",1.05,"auto","yes","no",0);
}

