// JavaScript Document

// *********** JQuery. ************* //
// *********** JQuery. ************* //

$(document).ready(function() {

// *********** Slide Show. ************* //

	//Show the paging and activate its first link
	$(".paging").show();
	$(".paging a:first").addClass("active");
	
	//Get size of the image, how many images there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageHeight = $(".window").height();
	var imageSum = $(".image_reel div").size(); /*substitute div for img*/
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	//adjust the div width & height
	$(".image_reel_div").css({'width' : imageWidth});
	$(".image_reel_div").css({'height' : imageWidth});


	//Paging and Slider Function
	rotate = function(){
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
		
		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
	
		//Slider Animation
		$(".image_reel").animate({
			left: -image_reelPosition
		}, 1000 );
	
	}; 
	
	//Rotation  and Timing Event
	rotateSwitch = function(){
		play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
			$active = $('.paging a.active').next(); //Move to the next paging
			if ( $active.length === 0) { //If paging reaches the end...
				//clearInterval(play);
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 14000); //Timer speed in milliseconds (7 seconds)
	};
	
	rotateSwitch(); //Run function on launch


	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation timer
	});	
	
	//On Click
	$(".paging a").click(function() {
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation timer
		return false; //Prevent browser jump to link anchor
	});
	

// *********** Support Options. ************* //
  $("#servicePlans").val("0");
  $('.serviceDiv').hide();
  $('#servicePlans').change(function() {
    $('.serviceDiv').hide();
    $('#div' + $(this).val()).slideDown('slow');
 });	
  
  
  
});



function playSlideshow(num,prefix){
	// Set prefix.
	if (prefix == 0) {
		var prefix = "";
	}
	else if (prefix == 1) {
		var prefix = "../";
	}		
	var screenNumber = num;
	$.get(prefix+'slideshow.cfm?screen='+num+'&prefix='+prefix, function(data, status) {
		jQuery.facebox(data);
	});
}

// *********** ColdFusion AJAX. ************* //
// *********** ColdFusion AJAX. ************* //

// Show contact info. 
function showContactInfo() {
	$(".contactInfoDiv").slideDown('slow');
}

//Open contact us window.
function openContactUs(prefix){
	// If window exists, destroy it.
	try{
	ColdFusion.Window.destroy('contactus',true);
	} catch (err) {}
	// Create new window.	
	var gen_config = {center:true,height:400,width:600,modal:true,resizable:false,initshow:true}
	ColdFusion.Window.create('contactus','Contact Us',prefix+'common/contactus.cfm',gen_config);
	ob = ColdFusion.Window.getWindowObject('contactus');
    ob.center();	
}

//Submit contact us form.
function sendContactUsForm(prefix) {	
	// Call ColdFusion form validation.
	var check = _CF_checkContactUsForm(document.forms.ContactUsForm);
	// If forms ok.
	if (check == true) {
		// Disable submit button.
		document.ContactUsForm.submit.disabled = true; 
		// AJAX loader.
		document.getElementById("loader").style.display = "";
		// Create instance of proxy. 
		var proxy = new WLMap.com.components();	
		// Set form. 
		proxy.setForm("ContactUsForm");
		// Set callback.
		proxy.setCallbackHandler(function(myResults) {
			popURL = prefix+"common/contactus.cfm?requestsent=yes";
			ColdFusion.navigate(popURL,'contactus');			
		})
		// Set error handling.
		proxy.setErrorHandler(function(statusCode, statusMsg){
			alert("Error "+statusCode+": "+statusMsg);
		})		
		// Set CFC.
		proxy.sendContactEmail();
	}
}

//Open portal link window.
function openPortalWindow(prefix) {	
	// If window exists, destroy it.
	try{
	ColdFusion.Window.destroy('portal',true);
	} catch (err) {}
	// Create new window.	
	var portal_config = {center:true,height:200,width:435,modal:true,resizable:false,initshow:true}
	ColdFusion.Window.create('portal','Portal Link',prefix+'common/portal_link.cfm',portal_config);	
	ob = ColdFusion.Window.getWindowObject('portal');
    ob.center();	
}

//Submit portal link form.
function submitPortalForm(prefix) {
	// Call ColdFusion form validation.
	var check = _CF_checkPortalForm(document.forms.PortalForm);
	// If forms ok.
	if (check == true) {
		// Create instance of proxy. 
		var proxy = new WLMap.com.components();			
		// Set form. 
		proxy.setForm("PortalForm");		
		// Set callback.
		proxy.setCallbackHandler(function(myResults) {
			popURL = prefix+"common/portal_link.cfm?url="+myResults;	
			ColdFusion.navigate(popURL,'portal');
		})
		// Set error handling.
		proxy.setErrorHandler(function(statusCode, statusMsg){
			alert("Error "+statusCode+": "+statusMsg);
		})		
		// Set CFC.
		proxy.getPortalLink();
	}
}

//Open demo window.
function openDemoWindow(prefix) {
	// If window exists, destroy it.
	try{
	ColdFusion.Window.destroy('demo',true);
	} catch (err) {}
	// Create new window.	
	var demo_config = {center:true,height:575,width:685,modal:true,resizable:false,initshow:true}
	ColdFusion.Window.create('demo','WiziLegal: Overview',prefix+'screencasts/overview_general/overview_general.html?prefix='+prefix,demo_config);
	ob = ColdFusion.Window.getWindowObject('demo');
    ob.center();
	ColdFusion.Window.onHide('demo',cleanup);
}

function cleanup() {
	ColdFusion.Window.destroy('demo',true);
}

function openFeatures(prefix){
	popURL=prefix + 'document-automation-and-assembly/virtual-law-office-and-document-automation-features.cfm';
	// Create new window.
	var feature_config = {center:true,height:500,width:375,modal:true,resizable:false,initshow:true}
	ColdFusion.Window.create('features','WiziLegal: Features',popURL,feature_config);	
	ob = ColdFusion.Window.getWindowObject('features');
    ob.center();	
}

function openPricing(prefix){
	popURL=prefix + 'document-automation-and-assembly/pricing-details.cfm';
	// Create new window.
	var feature_config = {center:true,height:300,width:500,modal:true,resizable:false,initshow:true}
	ColdFusion.Window.create('price','WiziLegal: Pricing Details',popURL,feature_config);	
	ob = ColdFusion.Window.getWindowObject('price');
    ob.center();	
}

function openFAQs(prefix){
	popURL=prefix + 'document-automation-and-assembly/faqs.cfm';
	// Create new window.
	var feature_config = {center:true,height:300,width:500,modal:true,resizable:false,initshow:true}
	ColdFusion.Window.create('faqs','WiziLegal: FAQs',popURL,feature_config);	
	ob = ColdFusion.Window.getWindowObject('faqs');
    ob.center();	
}

function openScreenShots(select_screen){
	popURL="../common/screen-shots.cfm?select_screen=" + select_screen;
	// Create new window.
	var screen_shots_config = {center:true,height:425,width:800,modal:true,resizable:false,initshow:true}
	ColdFusion.Window.create('screen_shots','WiziLegal: Screen Shots',popURL,screen_shots_config);	
	ob = ColdFusion.Window.getWindowObject('screen_shots');
    ob.center();	
}

function changeScreenShots(select_screen){
	popURL="../common/screen-shots.cfm?select_screen=" + select_screen;
	ColdFusion.navigate(popURL,'screen_shots');
}

// Open screencast tutorials.
function openScreencast(episode) {
	switch(episode) {
		case 1:
			var popURL = "../screencasts/overview_general/overview_general.html";
			var height = 575;
			break;
		case 2:
			var popURL = "../screencasts/overview_client/overview_client.html";
			var height = 650;
			break;			
		case 3:
			var popURL = "../screencasts/overview_administration/overview_administration.html";
			var height = 650;
			break;		
		default:
			var popURL = "../screencasts/overview_general/overview_general.html";
			var height = 575;
			break;			
	}	
	window.open(popURL,'Screencast','left=50,top=50,width=725,height='+height+',toolbar=0,resizable=1');
}

// Mouse over images.

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.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];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
