/* Author: Sheril Jebasingh, Email: mailsheril@gmail.com */
/* All rights reserved. Copying, distribution or disclosure without Author's permission is prohibited */
/* Date Created: Jan 20, 2009 */
/* Date Last Modified: Jan 20, 2009 */

// Global Navigation Animation
$(function() {
    $("div.mainNav ul li a").hover(
	// on mouse over
      function () {
		$(this).animate({
			opacity: 0
		}, "medium");
      },
	// on mouse out         
      function () {
		$(this).animate({
			opacity: 1
		}, "slow");
      });
});

// Home News 

// Product Highlight Navigation
$(function(){
	$("div.prodNav").hide();
	
	// eZee Desk
	$("div.desk a.more").mouseover(function(){
		$("div.link div.prodNav").hide("slow");
		$("div.web div.prodNav").hide("slow");
		$("div.manage div.prodNav").hide("slow");
		$("div.stay div.prodNav").hide("slow");
		$("div.connect div.prodNav").hide("slow");
		
		$("div.desk div.prodNav").show("slow");
	})	
	$("div.desk div.prodNav a").click(function(){
		$("div.desk div.prodNav").hide("slow");
	});
	
	// eZee Link
	$("div.link a.more").mouseover(function(){
		$("div.desk div.prodNav").hide("slow");
		$("div.web div.prodNav").hide("slow");
		$("div.manage div.prodNav").hide("slow");
		$("div.stay div.prodNav").hide("slow");
		$("div.connect div.prodNav").hide("slow");
		
		$("div.link div.prodNav").show("slow");
	})	
	$("div.link div.prodNav a").click(function(){
		$("div.link  div.prodNav").hide("slow");
	});
	
	// eZee Web
	$("div.web  a.more").mouseover(function(){
		$("div.desk div.prodNav").hide("slow");
		$("div.link div.prodNav").hide("slow");
		$("div.manage div.prodNav").hide("slow");
		$("div.stay div.prodNav").hide("slow");
		$("div.connect div.prodNav").hide("slow");
		
		$("div.web div.prodNav").show("slow");
	})	
	$("div.web div.prodNav a").click(function(){
		$("div.web  div.prodNav").hide("slow");
	});
	
	// eZee Manage
	$("div.manage  a.more").mouseover(function(){
		$("div.desk div.prodNav").hide("slow");
		$("div.link div.prodNav").hide("slow");
		$("div.web div.prodNav").hide("slow");
		$("div.stay div.prodNav").hide("slow");
		$("div.connect div.prodNav").hide("slow");
		
		$("div.manage div.prodNav").show("slow");
	})	
	$("div.manage div.prodNav a").click(function(){
		$("div.manage  div.prodNav").hide("slow");
	});
	
	// eZee Stay
	$("div.stay  a.more").mouseover(function(){
		$("div.desk div.prodNav").hide("slow");
		$("div.link div.prodNav").hide("slow");
		$("div.web div.prodNav").hide("slow");
		$("div.manage div.prodNav").hide("slow");
		$("div.connect div.prodNav").hide("slow");
		
		$("div.stay div.prodNav").show("slow");
	})	
	$("div.stay div.prodNav a").click(function(){
		$("div.stay  div.prodNav").hide("slow");
	});
	
	// eZee Connect
	$("div.connect  a.more").mouseover(function(){
		$("div.desk div.prodNav").hide("slow");
		$("div.link div.prodNav").hide("slow");
		$("div.web div.prodNav").hide("slow");
		$("div.manage div.prodNav").hide("slow");
		$("div.stay div.prodNav").hide("slow");
		
		$("div.connect div.prodNav").show("slow");
	})	
	$("div.connect div.prodNav a").click(function(){
		$("div.connect  div.prodNav").hide("slow");
	});
	

});

//Left Navigation
// Accordion List
//$(document).ready(function() {
//	$('div#secNav > div').hide();
//	$('div.secNav > h4').click(function(){
//		$(this).next('div').slideToggle('slow').siblings('div:visible').slideUp('slow')
//	});
//});

// Accordion List
//$(document).ready(function() {
//	$('div.faqContainer > div').hide();
//	$('div.faqContainer > h4').click(function(){
//		$(this).next('div').slideToggle('slow').siblings('div:visible').slideUp('slow')
//	});
//});



// For Modal Popup
// Find Browser Dimention
function pageWidth(){
	return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 
   
function pageHeight(){
	return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
} 

function posLeft(){
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
} 

function posTop(){
    return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
} 

function posRight(){
    return posLeft()+pageWidth();
}

function posBottom(){
    return posTop()+pageHeight();
}

//Scroll Height and Width
function getPageHeightWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
	}else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
	}else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight + document.body.offsetTop;
  	}
	return yWithScroll;
}

function getPageWidthWithScroll(){
	if (window.innerWidth && window.scrollMaxX) {// Firefox
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		xWithScroll = document.body.offsetWidth + document.body.offsetLeft;
  	}
	return xWithScroll;
}

//Modal Window
function showModal(pageUrl) {
	var custompagesFolder="";
	
	// for IE
	var browser=navigator.appName;
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
    
	var tempIframe = document.createElement('iframe');
	tempIframe.id = "modal";
	tempIframe.name = "modal";
	tempIframe.frameBorder = "0";
	tempIframe.scrolling="no";
	tempIframe.style.overflow = "hidden";
	tempIframe.allowTransparency=true;
	document.body.appendChild(tempIframe);
	tempIframe.src = custompagesFolder+ pageUrl;
	return false;
}

function CenterModal(width,height){
	var elementId = "modal";
	var visibleHeight = pageHeight();
	var visibleWidth = pageWidth();
	element = document.getElementById(elementId);
	element.width = width;
	element.height = height;
	if(element.height > visibleHeight){
		element.style.top = "20px";
	}else{
		element.style.top = (visibleHeight-element.height)/2 + "px";
	}
	element.style.left = (visibleWidth-element.width)/2 + "px";
	
	var totalHeight = getPageHeightWithScroll();
	var totalWidth = getPageWidthWithScroll();
	var tempCoverDiv = document.createElement('div');
	tempCoverDiv.id = "coverLayer";
	tempCoverDiv.style.height=totalHeight+"px";
	tempCoverDiv.style.width=totalWidth+"px";
	document.body.appendChild(tempCoverDiv);
	getScrollXY();
   	window.scrollTo(0,0);
}

function closeModalWindow() {
	var tempIframe = document.getElementById('modal');
	var tempCoverDiv = document.getElementById('coverLayer');
	if(tempIframe) tempIframe.parentNode.removeChild(tempIframe);
	if(tempCoverDiv) tempCoverDiv.parentNode.removeChild(tempCoverDiv);
	parent.window.scrollTo(xPos,yPos);
}

var xPos = 0, yPos = 0;
function getScrollXY() {
    if( typeof( window.pageYOffset ) == 'number' ) {
        // Netscape
        xPos = window.pageXOffset;
        yPos = window.pageYOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        // DOM
        xPos = document.body.scrollLeft;
        yPos = document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        // IE6 standards compliant mode
        xPos = document.documentElement.scrollLeft;
        yPos = document.documentElement.scrollTop;
    }
}

// Frequently Asked Questions
// Accordion List
$(document).ready(function() {
	$('div.faqContainer > div').hide();
	$('div.faqContainer > h4').click(function(){
		$(this).next('div').slideToggle('slow').siblings('div:visible').slideUp('slow')
	});
});

// Home Page News Scroller
jQuery.fn.accessNews = function( settings ) {
	settings = jQuery.extend({
        headline : "",
        speed : "normal",
		slideBy : 2
    }, settings);
    return this.each(function() {
		jQuery.fn.accessNews.run( jQuery( this ), settings );
    });
};
jQuery.fn.accessNews.run = function( $this, settings ) {
	jQuery( ".javascript_css", $this ).css( "display", "none" );
	var ul = jQuery( "ul:eq(0)", $this );
	var li = ul.children();
	if ( li.length > settings.slideBy ) {
		$("ul li").css("display", "block");
		var $next = jQuery( ".next > a", $this );
		var $back = jQuery( ".back > a", $this );
		var liWidth = jQuery( li[0] ).width();
		var animating = false;
		ul.css( "width", ( li.length * liWidth ) );
		$next.click(function() {
			if ( !animating ) {
				animating = true;
				offsetLeft = parseInt( ul.css( "left" ) ) - ( liWidth * settings.slideBy );
				if ( offsetLeft + ul.width() > 0 ) {
					$back.css( "display", "block" );
					ul.animate({
						left: offsetLeft
					}, settings.speed, function() {
						if ( parseInt( ul.css( "left" ) ) + ul.width() <= liWidth * settings.slideBy ) {
							$next.css( "display", "none" );
						}
						animating = false;
					});
				} else {
					animating = false;
				}
			}
			return false;
		});
		$back.click(function() {
			if ( !animating ) {
				animating = true;
				offsetRight = parseInt( ul.css( "left" ) ) + ( liWidth * settings.slideBy );
				if ( offsetRight + ul.width() <= ul.width() ) {
					$next.css( "display", "block" );
					ul.animate({
						left: offsetRight
					}, settings.speed, function() {
						if ( parseInt( ul.css( "left" ) ) == 0 ) {
							$back.css( "display", "none" );
						}
						animating = false;
					});
				} else {
					animating = false;
				}
			}
			return false;
		});
		$next.css( "display", "block" )
			.parent().after( [ "<p class=\"view_all\">", settings.headline, " - ", li.length, " total ( <a href=\"#\">view all</a> )</p>" ].join( "" ) );
		jQuery( ".view_all > a, .skip_to_news > a", $this ).click(function() {
			var skip_to_news = ( jQuery( this ).html() == "Skip to News" );
			if ( jQuery( this ).html() == "view all" || skip_to_news ) {
				ul.css( "width", "auto" ).css( "left", "0" );
				$next.css( "display", "none" );
				$back.css( "display", "none" );
				if ( !skip_to_news ) {
					jQuery( this ).html( "view less" );
				}
			} else {
				if ( !skip_to_news ) {
					jQuery( this ).html( "view all" );
				}
				ul.css( "width", ( li.length * liWidth ) );
				$next.css( "display", "block" );
			}
			return false;
		});
	}
};


// PAGE EDITIONS
// Show and Hide Tabs for the Features and SAAS Comparison
$(function() {
	$("div#saasComparison").hide();
	$("a#tabSaasComparison").click(function(){
		$("div#editionFeatures").fadeOut("slow");
		$("div#saasComparison").fadeIn("slow");
	});
	$("a#tabEditonFeatures").click(function(){
		$("div#saasComparison").fadeOut("slow");
		$("div#editionFeatures").fadeIn("slow");
	});
});
