jQuery.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});
	
	return this;
};

function imgCache() {
	var d=document;
	if(d.images) { 
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=imgCache.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}
	}
}

/* Cursor mod for Firefox */
$(document).ready(function () {
	$('.hand_cursor').mouseenter(function () {
		$(this).css('cursor','pointer');
	});
});


/* Site-specific functions: */


/* Cache the main nav menu alt images */
/*
$(document).ready(function () {
	imgCache(
		'/site/images/mn-blog-b.png',
		'/site/images/mn-contact-b.png',
		'/site/images/mn-features-b.png',
		'/site/images/mn-home-b.png',
		'/site/images/mn-sites-b.png'
		);
});
*/

/* Wipeout form boxes on focus */
$(document).ready(function () {

	var reverb = "";

	$('.inf').focus(function () {
		reverb = $(this).attr('value');
		$(this).attr('value','');
	});
	
	$('.inf').blur(function () {
		if ($(this).attr('value') == '')
		{
			$(this).attr('value', reverb);
		}
	});
	
});

/* Modal form submit */
/*
$(document).ready(function () {

	$('#inl_quote').submit(function () {
	
		var iframe_url = "/site/util/submit_form.php";
		$('body').append('<div id="mm_modal_bg"></div><div id="mm_modal_win"><iframe id="mm_modal_body" src="' + iframe_url + '" width="720" height="400"></div>');
	
	});

});
*/


function kill_iframe() {

	if (arguments[0]) {
		var ref = arguments[0];
	}
	else {
		var ref = "pe";
	}

	var modal_iframe = document.getElementById("mm_modal_body");
	modal_iframe.parentNode.removeChild(modal_iframe);

	$('#mm_modal_win').remove();
	$('#mm_modal_bg').remove();

	document.editor_form.return_ref.value=ref;
	document.editor_form.submit();
	
}

function kill_iframe_noform() {

	if (arguments[0]) {
		var ref = arguments[0];
	}
	else {
		var ref = "pe";
	}

	var modal_iframe = document.getElementById("mm_modal_body");
	modal_iframe.parentNode.removeChild(modal_iframe);

	$('#mm_modal_win').remove();
	$('#mm_modal_bg').remove();
	
	//window.location = window.location;

}


/* Image slider */

$(window).load(function () {

	var slidesWidth = $('#mdlls_slides').children().size() * 170;
	var sliderMargin = 0;

	$('#slider_rarr').click(function () {
		if (sliderMargin > (slidesWidth - ((2 * slidesWidth) - 510)))
		{
			$('#mdlls_slides').animate({ 'margin-left' : sliderMargin-510 }, 1000);
			sliderMargin -= 510;
		}
	});

	$('#slider_larr').click(function () {
		if (sliderMargin < 0)
		{
			$('#mdlls_slides').animate({ 'margin-left' : sliderMargin+510 }, 1000);
			sliderMargin += 510;
		}
	});

});


/* Image modals */

$(window).load(function () {

	var modalUp = 0;

	$('#mdlls_bg').click(function () {
		if (modalUp == 1)
		{
			$('#mdlls_modal').fadeOut(350);
			modalUp = 0;
			$(this).fadeOut(150);
		}
	});
	
	$('.mdlls_img').click(function () {
	
		var imgPath = $(this).attr('rel');
		$('#mdlls_bg').show();
		$('#mdlls_modal').html('<img src="'+imgPath+'" width="542" height="420">');
		$('#mdlls_modal').fadeIn(350);
		modalUp = 1;
	
	});

});


/* Smooth scroll arrows */

$(window).load(function () {

	$('.nav_arrow_btn').click(function () {
		tgtDiv = $(this).attr('rel');
		$('html, body').animate({ scrollTop: $('#'+tgtDiv).offset().top }, 1000);
	});

});


