var stopPreview;
var wrapperOn = false;
var whiteoutOn = false;
var ie6Fixon = false;
if (!window.XMLHttpRequest){
var IE6 = true;
}

function previewLoad(thisUrl){
    thisUrl += "?preview=true";
	$.ajax({
		url:thisUrl,
		cache: true,
		success: function(html){
			$(".preview-content .main-left").html($(html).find(".main-left .ajax-preview").html()).hide();
			$(".preview-content .main-right").html($(html).find(".main-right .ajax-preview").html()).hide();
			previewAnimation();
		}
	})
}

function previewAnimation(){
	if(IE6){
	{$('select').css({visibility:'hidden'});}
	}
	$(".preview-content, .preview-content .main-left").fadeIn(500,function(){
		$(".preview-content .main-right").slideDown(500,'linear');
	});		
}

function previewOff(){
$(".preview-content, .white-out").fadeOut(300,function(){
$(".preview-content, .white-out").remove();
	if(IE6){
	{$('select').css({visibility:'visible'});}
	}
$('.content-wrapper').css({position:'static'});
});
whiteoutOn = false;
}

function overLay(divArray){

if (!whiteoutOn)
{
	for(i=0;i<divArray.size();i++){

		thisDiv = $(divArray[i]);

		whiteOut = $("<div class='white-out'></div>").css({position:'absolute',height:thisDiv.height(),width:thisDiv.width(),background:'#ffffff',zIndex:98,opacity:0});
		contentWrapper = $("<div class='content-wrapper'></div>")
		if(!wrapperOn){thisDiv.find("> *").wrapAll(contentWrapper.css({width:thisDiv.width()}));}
		$('.content-wrapper').css({position:'absolute',zIndex:97});
		thisDiv.prepend(whiteOut);
	}

wrapperOn = true;

$(".white-out").css({opacity:0}).show().fadeTo(300,0.75);
}
whiteoutOn = true;
}

function previewOn(url){
previewLoad(url);

overLay($('#main , #header'));

previewContent= $('<div class="preview-content"><div class="main-left"></div><div class="main-right"></div></div>').css({position:'absolute',zIndex:99,background:'#ffffff',padding:'0 0 0 0',width:948,minHeight:343,paddingTop:$('.corp-home').css('padding-top')});

$('#main .white-out:first').before($(previewContent))
$(".white-out").mouseover(function(){previewOff();})

}

function setPreview(url){
		setTimeout(function(){
			if(!stopPreview){
				previewOn(url);}
		},330);
		stopPreview=false;
}

$(document).ready(function() {

	$("#nav a").hover(function() {
		setPreview($(this).attr('href'));
	}, function(){stopPreview=true;});
	
});



