/*
  jQuery Custom Functions 
  Author: Yahya Mubashir	
  Author URI: http://www.cressettech.com
*/
$(document).ready(function(){
		
		$("a.myvideo1").fancybox({
				'width'				: '55%',
				'height'			: '60%',
				'autoScale'			: true,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
		$("a.myvideotell").fancybox({
				'width'				: '54%',
				'height'			: '90%',
				'autoScale'			: true,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
		
			$("a.myvideo2").fancybox({
				'width'				: '48%',
				'height'			: '60%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			$("a.myvideo3").fancybox({
				'width'				: '48%',
				'height'			: '60%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
		
		
		$("a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
		
		
		$("#various1").fancybox({
				'width'				: '50%',
				'height'			: '75%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
		
			$("#various2").fancybox({
				'width'				: '75%',
				'height'			: '75%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});

			$("#various3").fancybox({
				'width'				: '80%',
				'height'			: '60%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});

			$("#various4").fancybox({
				'width'				: '80%',
				'height'			: '80%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			
			$("#various1img").fancybox({
				'width'				: '50%',
				'height'			: '75%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
		
			$("#various2img").fancybox({
				'width'				: '75%',
				'height'			: '75%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});

			$("#various3img").fancybox({
				'width'				: '80%',
				'height'			: '60%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});

			$("#various4img").fancybox({
				'width'				: '80%',
				'height'			: '80%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			
			$("#various_url").fancybox({
				'width'				: '80%',
				'height'			: '80%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			
			$("#various_url1").fancybox({
				'width'				: '80%',
				'height'			: '80%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			
			$("#various_url2").fancybox({
				'width'				: '80%',
				'height'			: '80%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
			
			$("#various_testimonial").fancybox({
				'width'				: '80%',
				'height'			: '80%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
		
		$('#slider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500, //Slide transition speed
		pauseTime:6000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
      	controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:false, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
		
		
		
		
		$('#401k').mouseover(function() {
	  		$('#sub_menu_401k').show();
			$('#sub_menu_additional_funding').hide();
			$('#sub_menu_equipment_financing').hide();
	  	});
		$('#additional_funding').mouseover(function() {
	  		$('#sub_menu_401k').hide();
			$('#sub_menu_additional_funding').show();
			$('#sub_menu_equipment_financing').hide();
	  	});
		$('#equipment_financing').mouseover(function() {
	  		$('#sub_menu_401k').hide();
			$('#sub_menu_additional_funding').hide();
			$('#sub_menu_equipment_financing').show();
	  	});
		
		$('.hide').mouseover(function() {
	  		$('#sub_menu_401k').hide();
			$('#sub_menu_additional_funding').hide();
			$('#sub_menu_equipment_financing').hide();
			$('#sub_menu_check_by_phone').hide();
			$('#sub_menu_echeck_online').hide();
			$('#sub_menu_check_guarantee').hide();
			$('#sub_menu_check_21').hide();
			$('#sub_menu_retail_restaurant').hide();
			$('#sub_menu_mail_phone_order').hide();
			$('#sub_menu_internet_processing').hide();
			$('#sub_menu_mobile_wireless').hide();
	  	});
		
		// for check processing menu
		$('#check_by_phone').mouseover(function() {
	  		$('#sub_menu_check_by_phone').show();
			$('#sub_menu_echeck_online').hide();
			$('#sub_menu_check_guarantee').hide();
			$('#sub_menu_check_21').hide();
	  	});
		$('#echeck_online').mouseover(function() {
	  		$('#sub_menu_check_by_phone').hide();
			$('#sub_menu_echeck_online').show();
			$('#sub_menu_check_guarantee').hide();
			$('#sub_menu_check_21').hide();
	  	});
		$('#check_guarantee').mouseover(function() {
	  		$('#sub_menu_check_by_phone').hide();
			$('#sub_menu_echeck_online').hide();
			$('#sub_menu_check_guarantee').show();
			$('#sub_menu_check_21').hide();
	  	});
		$('#check_21').mouseover(function() {
	  		$('#sub_menu_check_by_phone').hide();
			$('#sub_menu_echeck_online').hide();
			$('#sub_menu_check_guarantee').hide();
			$('#sub_menu_check_21').show();
	  	});
		
		// for merchant services menu
		
		$('#retail_restaurant').mouseover(function() {
	  		$('#sub_menu_retail_restaurant').show();
			$('#sub_menu_mail_phone_order').hide();
			$('#sub_menu_internet_processing').hide();
			$('#sub_menu_mobile_wireless').hide();
	  	});
		$('#mail_phone_order').mouseover(function() {
	  		$('#sub_menu_retail_restaurant').hide();
			$('#sub_menu_mail_phone_order').show();
			$('#sub_menu_internet_processing').hide();
			$('#sub_menu_mobile_wireless').hide();
	  	});
		$('#internet_processing').mouseover(function() {
	  		$('#sub_menu_retail_restaurant').hide();
			$('#sub_menu_mail_phone_order').hide();
			$('#sub_menu_internet_processing').show();
			$('#sub_menu_mobile_wireless').hide();
	  	});
		$('#mobile_wireless').mouseover(function() {
	  		$('#sub_menu_retail_restaurant').hide();
			$('#sub_menu_mail_phone_order').hide();
			$('#sub_menu_internet_processing').hide();
			$('#sub_menu_mobile_wireless').show();;
	  	});

// expression check 
/*^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$*/


// store url for current page as global variable
    current_page = document.location.href
 //alert(current_page);
    // apply selected states depending on current page
    if (current_page.match(/index/)) {
		//alert(current_page);
        $("ul.megamenu li:eq(0) a").addClass('selected');
		//$("ul.megamenu li:eq(0)").addClass('selected');
    }/* else if (
			  current_page.match(/business_cash_advance/) || 
			  current_page.match(/business_cash_advance_how_it_works/) ||
			  current_page.match(/business_cash_advance_getting_funded/) ||
			  current_page.match(/business_cash_advance_how_to_qualify/) ||
			  current_page.match(/why_choose_us/)) {
        $("ul.megamenu li:eq(1) a").addClass('selected');
    } else if (
			   current_page.match(/business_loans/) ||
			   current_page.match(/ira_401k_business_financing/) || 
			   current_page.match(/medical_financing/) || 
			   current_page.match(/equipment_leasing/) || 
			   current_page.match(/small_business_loans/) || 
			   current_page.match(/sba_loans/) || 
			   current_page.match(/working_capital/) ||
			   current_page.match(/restaurant_loans/) || 
			   current_page.match(/business_lines_of_credit/) || 
			   current_page.match(/unsecured_loans/) ||
			   current_page.match(/accounts_receivable_financing/) || 
			   current_page.match(/ira_401k_business_financing/) || 
			   current_page.match(/401k_business_financing_advantages/) ||
			   current_page.match(/401k_business_financing_how_it_works/) || 
			   current_page.match(/medical_financing/) || 
			   current_page.match(/minority_business_loans/) ||
			   current_page.match(/franchise_financing/) || 
			   current_page.match(/bad_credit_business_loans/) || 
			   current_page.match(/small_business_funding_other/) ||
			   current_page.match(/home_based_business_loans/) || 
			   current_page.match(/personal_business_loans/) || 
			   current_page.match(/commercial_loans/) ||
			   current_page.match(/small_business_loans_for_women/) || 
			   current_page.match(/canadian_funding/) || 
			   current_page.match(/merchant_check_advance/) ||
			   current_page.match(/new_business_loan/) || 
			   current_page.match(/fast_business_loans/) || 
			   current_page.match(/poor_credit_business_loans/) ||
			   current_page.match(/signature_loans/) || 
			   current_page.match(/venture_capital/) || 
			   current_page.match(/purchase_order_funding/) ||
			   current_page.match(/government_small_business_loan/) || 
			   current_page.match(/secured_loans/) || 
			   current_page.match(/restaurant_equipment_loans/) ||
			   current_page.match(/medical_equipment_loans/)
			   ) {
        $("ul.megamenu li:eq(2) a").addClass('selected');
    } else if (
			   current_page.match(/check_by_phone_group/) ||
			   current_page.match(/check_by_phone/) || 
			   current_page.match(/online_check_overview/) ||
			   current_page.match(/check_guarantee/) || 
			   current_page.match(/check_21/) || 
			   current_page.match(/check_conversion/) || 
			   current_page.match(/check_by_phone/) || 
			   current_page.match(/check_by_phone_how_it_works/) || 
			   current_page.match(/check_by_phone_why_us/) ||
			   current_page.match(/check_by_phone_rates_and_fees/) || 
			   current_page.match(/check_by_phone_frequently_asked_questions/) || 
			   current_page.match(/online_check_overview/) || 
			   current_page.match(/electronic_check_conversion_rates_and_fees/) || 
			   current_page.match(/electronic_check_conversion_payment_gateway/) || 
			   current_page.match(/electronic_check_conversion_check_verification/) ||
			   current_page.match(/electronic_check_conversion_faq/) || 
			   current_page.match(/check_21/) || 
			   current_page.match(/check_guarantee_frequently_asked_questions/) || 
			   current_page.match(/check_21/) || 
			   current_page.match(/check_21_equipment/)
			   ) {
        $("ul.megamenu li:eq(3) a").addClass('selected');
    }else if (
			   current_page.match(/merchant_services_group/) ||
			   current_page.match(/merchant_services/) ||
			   current_page.match(/mail_phone/overview/) ||
			   current_page.match(/merchant_service_moto_internet_overview/) ||
			   current_page.match(/wireless_and_mobile_credit_card_processing/) ||
			   current_page.match(/credit_card_machines/) ||
			   current_page.match(/point_of_sale_equipment/) ||
			   current_page.match(/lower_processing_rate/) ||
			   current_page.match(/merchant_services/) ||
			   current_page.match(/merchant_service_retail_processing_rates_and_fees/) ||
			   current_page.match(/merchant_service_retail_processing_faq/) ||
			   current_page.match(/mail_phone/overview/) ||
			   current_page.match(/merchant_service_moto_rates_and_fees/) ||
			   current_page.match(/merchant_service_moto_virtual_terminal/) ||
			   current_page.match(/merchant_service_moto_frequently_asked_questions/) ||
			   current_page.match(/merchant_service_moto_internet_overview/) ||
			   current_page.match(/merchant_service_internet_payment_gateway/) ||
			   current_page.match(/merchant_service_internet_rates_and_fees/) ||
			   current_page.match(/merchant_service_internet_ecommerce/) ||
			   current_page.match(/merchant_service_internet_faq/) ||
			   current_page.match(/merchant_service_internet_shopping_carts/) ||
			   current_page.match(/wireless_and_mobile_credit_card_processing/) ||
			   current_page.match(/merchant_service_mobile_wireless_rates_and_fees/) ||
			   current_page.match(/merchant_service_mobile_wireless_faq1/)
			   ) {
        $("ul.megamenu li:eq(4) a").addClass('selected');
    }*/

function extendPanel(event) {
    		var thisPanel = $(this).parents('.panel');
    		$('.panel .bar').unbind('click',extendPanel);
			$('.panel .bar').unbind('click',extendPanel);
    		expand.width = "960px"; expand.left = 0;
			collapse.width = + thisPanel.width(); collapse.left = thisPanel.position().left;
		  thisPanel
			.addClass('current')
			.css('zIndex',200)
		    .animate(expand,
		      'normal', function() { $('.panel.current .bar').one('click',returnPanels); $('.panel').not('.current').hide(); } );
		     $('.current .default').hide();
		     $('.current .extended').show('fast');
    	}
    	
    	function returnPanels(event) {
    		var thisPanel = $('.panel.current');
    		$('.panel.current .default').show();
    		$('.panel.current .extended').hide();
    		thisPanel
    			.css('top',0)
    			.animate(collapse,
    		'normal', function() { $('.panel .bar').bind('click',extendPanel); thisPanel.css('zIndex',2); thisPanel.removeClass('current'); });
    		$('.panel').show();
    	}
    	
		var expand = Object();
    	var collapse = Object();
    	
    	$('.changed').hide();
    	$('.panel .bar').bind('click',extendPanel);
    	$('.panel .learnMore').bind('click',extendPanel);
    	$('.panel .back').bind('click',returnPanels);
		
		
		function extendPanel1(event) {
    		var thisPanel1 = $(this).parents('.panel1');
    		$('.panel1 .bar1').unbind('click',extendPanel1);
    		expand.width = "650px"; expand.left = 0;
			collapse.width = + thisPanel1.width(); collapse.left = thisPanel1.position().left;
		  thisPanel1
			.addClass('current')
			.css('zIndex',200)
		    .animate(expand,
		      'normal', function() { $('.panel1.current .bar1').one('click',returnPanels1); $('.panel1').not('.current').hide(); } );
		     $('.current .default1').hide();
		     $('.current .extended1').show('fast');
    	}
    	
    	function returnPanels1(event) {
    		var thisPanel1 = $('.panel1.current');
    		$('.panel1.current .default1').show();
    		$('.panel1.current .extended1').hide();
    		thisPanel1
    			.css('top',0)
    			.animate(collapse,
    		'normal', function() { $('.panel1 .bar1').bind('click',extendPanel1); thisPanel1.css('zIndex',2); thisPanel1.removeClass('current'); });
    		$('.panel1').show();
    	}
    	
		var expand1 = Object();
    	var collapse1 = Object();
    	
    	$('.changed').hide();
    	$('.panel1 .bar1').bind('click',extendPanel1);
    	$('.panel1 .learnMore1').bind('click',extendPanel1);
    	$('.panel1 .back1').bind('click',returnPanels1);


$(function() {
		$( "#accordion" ).accordion({
			collapsible: true,
			autoHeight: false
		});
	});
$(function() {
		$("#tabs").tabs();
	});

jQuery(function(){
        var SelfLocation = window.location.href.split('?');
        switch (SelfLocation[1]) {
          case "justify_right":
            jQuery(".megamenu").megamenu({ 'justify':'right' });
            break;
          case "justify_left":
          default:
            jQuery(".megamenu").megamenu();
        }
      });



$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="images/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;
});

//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
    return false;
});
});

$(function() {
$(".btn").click(function() {
	var name = $("#name").val();	
	var email = $("#email").val();
	var ph = $("#ph").val();
	var bl = false;	
	
	
	if(name=='' || name=='Name:')
	{	
    	$('.error1').show();
		bl=true;
	}	
	else
	{	
		$('.error1').hide();
	}
	
	
	
	
	if(email=='' || email=='E-mail:')
	{
    	$('.error2').show();
		bl=true;
	}	
	else
	{
		var RegExEmail = /^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/;
		if (!RegExEmail.test(email))
		{
			$('.error2').hide();
			$('.error2a').show();
			bl=true;
		}
		else
		{
			$('.error2').hide();
			$('.error2a').hide();
		} 
	
	}
		
	
	if(ph=='' || ph=='Phone:')
	{	
    	$('.error3').show();
		bl=true;
	}	
	else
	{	
		$('.error3').hide();
	}
	
						
	if(bl==true)
		{

		}
	else
	{
		
		ajaxFunctionForQuery();			
		}
    
	return false;
	});
	
});



function ajaxFunctionForQuery()
{
	xmlHttp = GetXmlHttpObject();

    if (xmlHttp==null)
    {
         alert ("Your browser does not support AJAX!");
          return;
    } 
		var url="js/form_validation/ajaxFunctionForQuery.php";		
		var queryString = "?name=" + document.getElementById("name").value + "&comp=" + document.getElementById("comp").value + "&email=" + document.getElementById("email").value + "&ph=" + document.getElementById("ph").value + "&interest=" + document.getElementById("interest").value + "&timeline=" + document.getElementById("timeline").value + "&ref=" + location.href;
		url=url+queryString;
		//alert(url);
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);		
		xmlHttp.send(null);
} 

function stateChanged()
{
if (xmlHttp.readyState==4)
{
//alert(xmlHttp.responseText);
document.getElementById("lbl1").style.display='';
document.getElementById("commentForm").style.display="none";
//document.getElementById("lbl1").innerHTML = xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


jQuery.fn.megamenu = function(options) {
  options = jQuery.extend({}, options);
};


