/*
 * ExaVault Common JavaScript
 *
 * Contains generally used JS code for the ExaVault system
 *
 * NOTE: we have to use the full jQuery variable in all of our code, rather
 * then $, because Dokuwiki also uses $. Therefore. we're running jQuery with
 * noConflict() on: http://api.jquery.com/jQuery.noConflict/
 *
 * Written by D. Ordal
 * October 20, 2009
 *
 */

// Make sure the ExaVault namespace exists
var $EV = window.exavault || {};

/*
 * tooltipInit(): initialize tooltips
 *
 */
$EV.tooltipInit = function() {
	
	jQuery(".inlineTooltip").each(function(){ 
    	var el = jQuery(this); 
	    el.tooltip({ 
	        effect: 'slide',
	        tip : '#' + el.attr("id") + '-content',
	        delay: 0
	    }); 
	}); 
}

/*
 * overlayInit(): initialize overlay
 *
 */
$EV.overlayInit = function() {
	
	jQuery(".inlineOverlay").each(function(){ 
    	var el = jQuery(this); 
	    el.overlay({ 
	        target : '#' + el.attr("id") + '-content',
	        expose : {color: '#6F6F6F', loadSpeed: 250, closeSpeed: 100}
	    }); 
	}); 
}

/*
 * getUrlParam(): Get a parameter from the querystring
 *
 * @param name the name of the parameter to get
 */
$EV.getUrlParam = function(name){
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
	if (!results) { return null; }
	return results[1] || null;
}

/*
 * openWindow(): open a new window
 *
 * @param	theURL		string	the URL to open
 * @param	winName		name of the new window
 * @param	features 	optional features of the window
 *
 */
$EV.openWindow = function(theURL,winName,features) {
  window.open(theURL,winName,features);
  return false;
}

/*
 * attachHomepageListener(): attach onclick listeners to the pricing and promo divs
 *
 */
$EV.attachHomepageListener = function() {
	var mainPageURL = function() {
		switch (site){
			case EV_CONSTANTS.SITE_EXAVAULT:
				return "/ftp-storage-space/";
			break;
			case EV_CONSTANTS.SITE_EVBACKUP:
				return "/open-remote-backup/";
			break;
		}
	}

	var mainPageClick = function() {
		window.location.href=mainPageURL();
	}
	
	jQuery('#mainPromo').click(mainPageClick);
	jQuery('#mainPrices').click(mainPageClick);
	jQuery('.mainTeaserContainer').click(mainPageClick);
	
}

jQuery(document).ready( function(){
 	$EV.tooltipInit();
 	$EV.overlayInit();
	$EV.attachHomepageListener();
});
