// JavaScript Document
$(document).ready(function() {
	
	// Superfish menu drop down function call
	$('.sf-menu').superfish({
		delay: 200							
	});
	$('span.sf-sub-indicator').remove();
	
	// function to make equal heights of the div
	// function executes only if condition matches
	if( $('.equal-tri-cols .col .desc').length > 0 ){
		var greatestHt = 0;
		var block = $('.equal-tri-cols .col .desc'); 
		block.each( function(){	
			var curHt = $(this).height();	
			if( curHt > greatestHt ){
				greatestHt = curHt;	
			}	
		});
		block.css('height',greatestHt);
	}
	
	/* Slideshow for Testimonial */
	/*============================*/
	var TotalHeight = 0;
	$(".testimonial .testimonial-block").css({ opacity:0 });
	$(".logos").css({ opacity:0 });
	
	

	$(".testimonial .testimonial-block:first").addClass('current').css({ opacity:1 });
	$(".logos:first").addClass('current').css({ opacity:1 });
		
	//var boxHt = $(".testimonial .testimonial-block:first").height();
	$(".testimonial").animate({ height: $(".testimonial .testimonial-block:first").height() + 40 }, 200);
	
	setInterval("rotatorTestimonials()",6000);
	setInterval("rotatorLogos()",10000);
		
});

function rotatorTestimonials(){
	var oCurPhoto = $('.testimonial div.current');
	
	var oNxtPhoto = oCurPhoto.next();
	

	if(oNxtPhoto.length == 0 )
		oNxtPhoto  = $(".testimonial .testimonial-block:first");
		
	oCurPhoto.removeClass('current').addClass('previous').css({ opacity:0 });
	$(".testimonial .testimonial-block").css({ opacity:0 });
	oNxtPhoto.css({ opacity:0 }).addClass('current').animate({ opacity: 1}, 1000,
	   function(){
		   oCurPhoto.removeClass('previous');
	})
	$(".testimonial").animate({ height: $(".testimonial div.current").height() + 40 }, 200);
}
function rotatorLogos(){
	var oCurPhoto = $('.logos.current');
	
	var oNxtPhoto = oCurPhoto.next();
	

	if(oNxtPhoto.length == 0 )
		oNxtPhoto  = $(".logos:first");
		
	oCurPhoto.removeClass('current').addClass('previous').css({ opacity:0 });
	oNxtPhoto.css({ opacity:0 }).addClass('current').animate({ opacity: 1}, 1000,
	   function(){
		   oCurPhoto.removeClass('previous');
	})
}

// function to make the sf-menuu dropdown content within the wrapper.
$(function() {
    var $mainNav = $('#nav ul'),
    navWidth = $mainNav.width();
	navWidth = navWidth - 28; // only for this theme
	
    $mainNav.children('li').hover(function(ev) {
        var $this = $(this);
		if($this.parent().hasClass('sf-menu')){  // condition for only first level / immediate drop down
        	$dd = $this.children('ul');
		}
		else{
			$dd2 =	$this.children('ul');
		}
        // get the left position of this tab
		// condition if menu item [a tag] has class=sf-with-ul
		// condition if menu item [li tag] parent [ul tag] has class=sf-menu (ie. root level)
		if( $(this).find('a').hasClass('sf-with-ul') ){

			var leftPos = $this.find('.sf-with-ul').position().left;

			// get the width of the dropdown
			var ddWidth = $dd.width(),
			leftMax = navWidth - ddWidth;
			//alert("leftPos :" + leftPos +" , ul Width : " + ddWidth +" , navWidth : " + navWidth +" , leftMax : " + leftMax);
			
			if( $(this).parent().hasClass('sf-menu') ){
			// position the dropdown
				$dd.css('left', Math.min(leftPos, leftMax) );
			
			}
			else{
				var ddLeftRoot = $(this).parent().position().left,
				ddWidthRoot = $(this).parent().width(),
				ddWidthChild = $dd2.width(),				
				leftMaxChild = ddLeftRoot + ddWidthRoot + ddWidthChild,
				rightPos = leftPos - ddWidthChild;
				
				var ddTop = $this.find('.sf-with-ul').position().top;	
				$dd2.css('left', (leftMaxChild < navWidth) ? ddWidthRoot : rightPos );
				$dd2.css('top', ddTop );
			}
        
        	// show the dropdown
        	//$this.addClass('main-nav-item-active');

		}
    }, function(ev) {

        // hide the dropdown
        //$(this).removeClass('main-nav-item-active');
    });
});

// flash version checking
function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}

// google analytic function
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

try {
var pageTracker = _gat._getTracker("UA-9369886-1");
pageTracker._trackPageview();
} catch(err) {}


