// JavaScript Document
/*
*
* This file contains the common functions required for all the feauters through out the sites
* and will be included in all the templates. Remove this and 60% of the site functionality goes out
*/
function forMenuHover()
{
    jQuery('#nav-menu > li').hover(
        function()
        {
            jQuery(this).addClass('mega-hover');
            jQuery(this).children('div').children('.sub').stop(true, true).fadeIn(1);

        },function()
        {
            jQuery(this).removeClass('mega-hover');
            jQuery(this).children('div').children('.sub').stop(true, true).slideUp(1);
        }
    );
}

function forSlideShow()
{
    jQuery(function()
    {
	 jQuery("#slides").slides({
            //preload: true,
            //preloadImage: '../theme/loading.gif',
            play: 5000,
            pause: 50,
            hoverPause: true
	});
    });
}
function forTabs()
{
    jQuery(function(){
                    // Tabs
                    jQuery('#tabs').tabs();
                    //hover states on the static widgets
                    jQuery('#dialog_link, ul#icons li').hover(
                            function() { jQuery(this).addClass('ui-state-hover'); },
                            function() { jQuery(this).removeClass('ui-state-hover'); }
                    );

		});
}
function forTabsSpecial()
{
	jQuery(function(){	
				// Tabs
				jQuery('#tabs-special').tabs({ selected:-1 });				
				//hover states on the static widgets
				jQuery('#dialog_link, ul#icons li').hover(
					function() { jQuery(this).addClass('ui-state-hover'); }, 
					function() { jQuery(this).removeClass('ui-state-hover'); }
				);
				
			});
}
function redirectDemoCenterToHashes()
{
	//var hashPart;
    firstPart = window.location.href.split(/demos\//)[0];
    secondPart = window.location.href.split(/demos\//)[1].split("/")[0];
    hashPart = window.location.href.split(/demos\//)[1].split("/")[1];
	//alert(secondPart+"1");
    if(hashPart !==null && hashPart != '' && hashPart.indexOf("#")== -1)
    {
            finalUrl = firstPart + "demos/" + secondPart;
            hashedUrl = "/#" + hashPart.replace(/\/$/, "");
            finalUrl = finalUrl + hashedUrl;			
            window.location = finalUrl;
    }
}


function showToolTip()
{
		
	jQuery('.tips-icon').mouseover(function() {
		var lasttips = jQuery(this).hasClass('last');
		var x = jQuery(this).position().left;
		var y = jQuery(this).position().top;
		if (lasttips==false) {
		jQuery(this).parent().find('.tool-tip-holder').css({left:x+15,top:y-27});
		}
		else {
			jQuery(this).parent().find('.tool-tip-holder').css({left:x-228,top:y-27});
			jQuery(this).parent().find('.tool-tip-holder').addClass('last-tips');
		}
		jQuery(this).parent().find('.tool-tip-holder').stop(true, true).fadeIn('fast');		
		}).mouseout(function() {
			 var tooltip = jQuery(this).parent().find('.tool-tip-holder');
			 tooltip.mouseover( function() {
				 tooltip.stop(true, true)
				 tooltip.show()
			 }).mouseout(function() {
				 tooltip.fadeOut('slow')
			 });
			 tooltip.fadeOut('slow');
		
		 });
} 


/*function showToolTip()
{
	var config = {    
 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
 interval: 200, // number = milliseconds for onMouseOver polling interval    
 over:  MouseOnTipsIcon, // function = onMouseOver callback (REQUIRED)    
 timeout: 500, // number = milliseconds delay before onMouseOut    
 out: MouseOffTipsIcon // function = onMouseOut callback (REQUIRED)
};

 
	jQuery('.tips-icon').hoverIntent(config)


}

function MouseOnTipsIcon(){ 

        var lasttips = jQuery(this).hasClass('last');	
		var x = jQuery(this).position().left;
		var y = jQuery(this).position().top;		
		if (lasttips==false) {		
		jQuery(this).parent().find('.tool-tip-holder').css({left:x+15,top:y-27});
		}
		else {
			jQuery(this).parent().find('.tool-tip-holder').css({left:x-228,top:y-27});
			jQuery(this).parent().find('.tool-tip-holder').addClass('last-tips');
		}
		jQuery(this).parent().find('.tool-tip-holder').stop(true, true).fadeIn('fast');		
		}
function  MouseOffTipsIcon(){ 
var tooltip = jQuery(this).parent().find('.tool-tip-holder');
			 tooltip.mouseover( function() {
				 tooltip.stop(true, true)
				 tooltip.show()
			 }).mouseout(function() {
				 tooltip.fadeOut('slow')
			 });
tooltip.fadeOut('slow');}


*/
function showOptionBox() {	
	
	jQuery('.checkbox').click(function() {
	 if( jQuery(this).is(':checked') ) {
		 jQuery(this).parent().find('.option-block').slideDown("slow");


	 }
	 else {
		  jQuery(this).parent().find('.option-block').slideUp("slow");

	 }
	});
}



function toggleFaq()
{
	 jQuery('.faq-list li a').click ( function () {
		 var ele = jQuery(this).next('p');
		 var ele1 = jQuery(this).next('div');
		 var show = jQuery(this).next('p').css('display');
		 var show1 = jQuery(this).next('div').css('display');

		 jQuery('p.faq-cont').fadeOut('fast');
		 jQuery('div.faq-cont').fadeOut('fast');

		 if ( show == 'none') {
			 ele.fadeIn('fast');
		 }
		 if ( show1 == 'none') {
			 ele1.fadeIn('fast');
		 }
	 });
}



function showMoreInCaseStudy()
{
	jQuery(
		function () 
		{
			var $table = jQuery('#cstud'), links = jQuery('label.link.expander');
			links.click(
				function () 
				{
					jQuery(this).hide().parent().next().fadeIn('medium');
				});
		});	
}


function showMore() {
	
	jQuery('.more').click (function() {		
		jQuery(this).parent().find('.more-info-block').slideToggle('slow', function() {
				jQuery(this).toggleClass('open');
				if(jQuery(this).is('.open')){
					jQuery(this).parent().find('.more').addClass('openstate').find('span').html('Hide');
					
				}
				else {
					jQuery(this).parent().find('.more').removeClass('openstate').find('span').html('Show more');
				}
  			});

	});
}


function showWPform() { 
        jQuery(".whitepaper-link").fancybox({
		'titleShow' : false,
		'autoScale' : false,
		'centerOnScroll' : true,
		'autoDimensions': true
		
	});
	
}

function formatTitle(title, currentArray, currentIndex, currentOpts) {
            return '<div id="tip7-title">' + (title && title.length ? '<b>' + title + '</b>' : '' )  + '(' +(currentIndex + 1) + ' of ' + currentArray.length + ')'+ '</div>';
}





function showCompform() { 
        jQuery(".comp-link").fancybox({
		'titleShow' : false,
		'autoScale' : false,
		'centerOnScroll' : true,
		'autoDimensions': false,
		'width' : 780,
		ajax : {
                type	: "GET",
                data	: 'fromlightbox=yes'
             }
		
	});
	
}

function formatTitle(title, currentArray, currentIndex, currentOpts) {
            return '<div id="tip7-title">' + (title && title.length ? '<b>' + title + '</b>' : '' )  + '(' +(currentIndex + 1) + ' of ' + currentArray.length + ')'+ '</div>';
}











function showPrivacyPolicy() { 
        jQuery(".privacy_link").fancybox({
		'titleShow' : false,
		'autoScale' : false,
		'centerOnScroll' : true,
		'autoDimensions': false,
		'width': 600,
		'height': 500,
		    ajax : {
                type	: "GET",
                data	: 'fromlightbox=yes'
             }
		
	});
	
}

function formatTitle(title, currentArray, currentIndex, currentOpts) {
            return '<div id="tip7-title">' + (title && title.length ? '<b>' + title + '</b>' : '' )  + '(' +(currentIndex + 1) + ' of ' + currentArray.length + ')'+ '</div>';
}


/*function showTicker() { 
jQuery(function()
{
    jQuery('#ticker').each(function()
    {
        var ticker = jQuery(this);
        var fader = jQuery('<span class="fader">&nbsp;</span>').css({display:'inline'});
        var links = ticker.find('ul>li>a');
        ticker.find('ul').replaceWith(fader);

        var counter = 0;
        var curLink;
        var fadeSpeed = 600;
        var showLink = function()
            {
                var newLinkIndex = (counter++) % links.length;
                var newLink = jQuery(links[newLinkIndex]);
                var fadeInFunction = function()
                    {
                        curLink = newLink;
                        fader.append(curLink).fadeIn(fadeSpeed);
                    };
                if (curLink)
                {
                    fader.fadeOut(fadeSpeed, function(){
                        curLink.remove();
                        setTimeout(fadeInFunction, 0);
                    });
                }
                else
                {
                    fadeInFunction();
                }
            };

        var speed = 5500;
        var autoInterval;

        var startTimer = function()
        {
            autoInterval = setInterval(showLink, speed);
        };
        ticker.hover(function(){
            clearInterval(autoInterval);
        }, startTimer);

        fader.fadeOut(0, function(){
            fader.text('');
            showLink();
        });
        startTimer();

    });
});
};*/


function showTicker() { 
jQuery(function()
{
    jQuery('#ticker').each(function()
    {
        var ticker = jQuery(this);
        var fader = jQuery('<span class="fader">&nbsp;</span>').css({display:'inline'});
        var links = ticker.find('ul>li');
		var linkHtml = ticker.find('ul>li').html();
		//alert(links.length);
		
        ticker.find('ul').replaceWith(fader);

        var counter = 0;
        var curLink;
        var fadeSpeed = 600;
        var showLink = function()
            {
				//alert(counter);
                var newLinkIndex = (counter++) % links.length;
                var newLink = jQuery(links[newLinkIndex]);
				//alert(newLink.html());
				
                var fadeInFunction = function()
                    {
                        curLink = newLink;		
						//curLink = links;
						fader.html("");
                        fader.append(newLink.html()).fadeIn(fadeSpeed);
                    };
                if (curLink)
                {
                        fader.fadeOut(fadeSpeed, function(){
						fader.html("");
                       // curLink.remove();
                        setTimeout(fadeInFunction, 0);
                    });
                }
                else
                {
                    fadeInFunction();
                }
            };

        var speed = 5500;
        var autoInterval;

        var startTimer = function()
        {
            autoInterval = setInterval(showLink, speed);
        };
        ticker.hover(function(){
            clearInterval(autoInterval);
        }, startTimer);

        fader.fadeOut(0, function(){
            fader.text('');
            showLink();
        });
        startTimer();

    });
});
};




function specialNav() {
	jQuery(".special-nav .sub-nav li a").hover(
	  function () {
	   jQuery(this).parent("li").addClass("hover");
	  },
	  function () {
		jQuery(this).parent("li").removeClass("hover");
	  }
	);
	
	jQuery(".special-nav .sub-nav li a.active").parent("li").addClass("active")
};


function CallToAction() {
	jQuery(".action_btn a").hover(									 
	  function () {		
	   jQuery(this).parent().parent().parent(".action_btn").addClass("hover");
	  },
	  function () {
		jQuery(this).parent().parent().parent(".action_btn").removeClass("hover");
	  }		  	
	);
	
};




jQuery(document).ready(
    function()
    {		
        forMenuHover();
        if( typeof(jQuery("#slides"))== 'object' && jQuery("#slides")!==null && jQuery("#slides").html()!==null)
		  forSlideShow();		
        if( typeof(jQuery("#tabs"))== 'object' && jQuery("#tabs")!==null)
            forTabs();
		if( typeof(jQuery(".faq-list li a"))== 'object' && jQuery(".faq-list li a")!==null)
			toggleFaq();
		if( typeof(jQuery(".tips-icon"))== 'object' && jQuery(".tips-icon")!==null)
			showToolTip();
		if( typeof(jQuery("#tabs-special"))== 'object' && jQuery("#tabs-special")!==null)
			forTabsSpecial();
		if(typeof(jQuery("label.link.expander"))== 'object' && jQuery("label.link.expander")!==null)
			showMoreInCaseStudy()
	    if(typeof(jQuery(".division-block .more"))== 'object' && jQuery(".division-block .more")!==null)
			showMore()			
	    if(typeof(jQuery(".option-block"))== 'object' && jQuery(".option-block")!==null)		
			showOptionBox() 
		 if(typeof(jQuery(".whitepaper-link"))== 'object' && jQuery(".whitepaper-link")!==null)		
			showWPform()	
		if(typeof(jQuery(".privacy_link"))== 'object' && jQuery(".privacy_link")!==null)		
			showPrivacyPolicy()				
	    if(typeof(jQuery("#ticker"))== 'object' && jQuery("#ticker")!==null)		
			showTicker()		
		 if(typeof(jQuery(".special-nav"))== 'object' && jQuery(".special-nav")!==null)		
			 specialNav()	
		 if(typeof(jQuery(".comp-link"))== 'object' && jQuery(".comp-link")!==null)		
			showCompform()
        if(typeof(jQuery(".action_btn"))== 'object' && jQuery(".action_btn")!==null)		
			CallToAction()
	
	
			
    }
);
