// JavaScript Document

jQuery(document).ready(function(){

//--Labelify inits
	jQuery(".www").labelifyWWW();
	jQuery(":text").labelify();
	jQuery(":password").labelify();
	jQuery("textarea").labelify();
//--
	
	
//--Tabber (jQuery UI) inits
   	jQuery(".tabs").tabs();
//--

	
//--Form focus init
	jQuery("input, textarea").focus(
	function()
	{
		// only select if the text has not changed
		if(this.value == this.defaultValue)
		{ this.select(); }
		}
	);
//--
	
//--Call-to-Action Pager init
	jQuery('#cta-slider').before('<ul id="cta_pager">').cycle({
		fx: 	'fade',
		next:   '#cta_right', 
		prev:   '#cta_left',
		
		pager:	'#cta_pager',
		activePagerClass: 'active_slide',
		pagerAnchorBuilder: function(idx, slide) { 
        	return '<li><a href="#"></a></li>'; 
 		},
	
		timeout:8000,
		speed:	1000
	});
	jQuery('#cta_pager_pause').toggle(function() { 
		jQuery('#cta-slider').cycle('pause'); 
		jQuery('#cta_pager_pause').attr('style',"background:url('../images/cta_pager_play.gif') no-repeat center;"); 
		}, function() { 
		jQuery('#cta-slider').cycle('resume'); 
		jQuery('#cta_pager_pause').attr('style',"background:url('../images/cta_pager_pause.gif') no-repeat center;"); 
    });
//--

//--Call-to-Action lightbox init
	jQuery("#cta_lightbox_1").colorbox({
		width:"690px", 
		height:"435px", 
		onOpen:function(){ 
			jQuery('#cta-slider').cycle('pause'); 
			jQuery('#cta_pager_pause').attr('style',"background:url('../images/cta_pager_play.gif') no-repeat center;"); 
		},
		onCleanup:function(){
			jQuery('.cta_lightbox_p').remove();
		},
		onClosed:function(){
			jQuery('#cta-slider').cycle('resume'); 
			jQuery('#cta_pager_pause').attr('style',"background:url('../images/cta_pager_pause.gif') no-repeat center;");
		}
	});
//--


//--jQuery Form Validation init - validationEngine.js
   	jQuery("#quick-quote").validationEngine({validationEventTriggers:"blur", success : function() { clickload(); this.submit(); }});
	//jQuery("#free-website-analysis").validationEngine({validationEventTriggers:"blur", promptPosition: "topLeft", scroll: false, success : function() { clickload(); this.submit(); }});
	jQuery("#ct-login").validationEngine({validationEventTriggers:"blur", success : function() { clickload(); this.submit(); }});
	jQuery("#newsletter-form").validationEngine({validationEventTriggers:"blur", success : function() { clickload(); this.submit(); }});
	jQuery("#contact").validationEngine({validationEventTriggers:"blur", success : function() { clickload(); this.submit(); }});
	jQuery("#contactus").validationEngine({validationEventTriggers:"blur", success : function() { clickload(); this.submit(); }});
//--

//-- jQuery Form Validation init - validate.js
	jQuery("#free-website-analysis").validate();
//--
	
//--Tablesorter init
	jQuery("#myTable").tablesorter();
//--


//-- Social buttons - async loading ;  FB appId:127760087237610
/* G+ */
/*(function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })(); */
/* FB */
/*window.fbAsyncInit = function() { FB.init({ appId: '127760087237610', status: true, cookie: true, xfbml: true }); };
  (function() {
    var e = document.createElement('script');
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('Facebook').appendChild(e);
  }());*/
/* Twitter */  
/*(function() {
        var twitterScriptTag = document.createElement('script');
        twitterScriptTag.type = 'text/javascript';
        twitterScriptTag.async = true;
        twitterScriptTag.src = 'http://platform.twitter.com/widgets.js';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(twitterScriptTag, s);
})();   */
//--

//-- Sidebar Contact Form init --
	$('#Free_Website_Analysis_Form').animate({width: "50px"}, {queue:false, duration: 850, easing: 'easeOutBounce'});    
	
    //Increment the idle time counter every minute.
    var idleInterval = setInterval("timerIncrement()", 1000); // 1 second
	
	var isClosing = "false";
	
    //Zero the idle timer on mouse movement.
    $(this).mousemove(function (e) {
        idleTime = 0;
    });
    $(this).keypress(function (e) {
        idleTime = 0;
    });	
	
	$('#Free_Website_Analysis_Form').hover(function() {
		if(isClosing != "true")
		{
			$(this).addClass('Open'); 
			$(this).animate({width: "280px"}, {queue:false, duration: 850, easing: 'easeOutBounce'})
			$(this).unbind('hover');
		}
	});
	
	$('#Free_Website_Analysis_Form #Toggle').click(function() {
		$('#Free_Website_Analysis_Form').removeClass('Open'); 

		isClosing = "true";
		$('#Free_Website_Analysis_Form').animate({width: "50px"}, {queue:false, duration: 850, easing: 'easeOutBounce', 'complete':function(){isClosing = "false"}}).delay(10000).unbind('hover');;
	});	
//--

});

//-- for Sidebar Contact form init --
function timerIncrement() {
    idleTime = idleTime + 1;
    if(idleTime > 10) { 
		$('#Free_Website_Analysis_Form').removeClass('Open'); 
		$('#Free_Website_Analysis_Form').animate({width: "50px"}, {queue:true, duration: 850, easing: 'easeOutBounce'})  		
    }
}
//--


//--Popup loader init (legacy)
var popup = new Popup();
popup.autoHide = false;
popup.content = '<img src="/images/popup_loader.gif" alt="Loader">';
popup.width=200;
popup.height=200;
popup.style = {};
function clickload()
{
	popup.show();
	jQuery("#container").css("opacity","0.4");
}
//--


//--JS IE Detection hack
function isIE()
{	
	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}
//--
