﻿// This file contains all custom JavaScript for Manticore


/* Primary Navigation JavaScript */
window.onload = function() {
    if (document.getElementById("primaryNavigationWrapper") != null){
	    var sfEls = document.getElementById("primaryNavigationWrapper").getElementsByTagName("LI");
	    for (var i=0; i<sfEls.length; i++) {
		    sfEls[i].onmouseover=function() {
			    this.className+=" sfhover";
		    }
		    sfEls[i].onmouseout=function() {
			    this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		    }
	    }
	}
	
	// Select the navigation
	var currentUrl = window.location.href.toString().toLowerCase();		
	if ( currentUrl == "http://localhost:2377/" || currentUrl == "http://www.iperform3d.com/" || currentUrl == "http://www.iperform3d.com/default.aspx" || currentUrl == "http://www.iperform3d.com/landing.aspx" ){
	    document.getElementById("navHome").className += "active";
	}
	if ( currentUrl.indexOf("welcome-to-iperform3d")!=-1 ){
	    document.getElementById("navHome").className += "active";
	}
	if ( currentUrl.indexOf("howitworks")!=-1 ){
	    if(document.getElementById("navHowItWorks") != null)
	    {
	    	document.getElementById("navHowItWorks").className += "active";
	    }
	}
	if (currentUrl.indexOf("/buy.aspx")!=-1 || currentUrl.indexOf("/join.aspx")!=-1 || currentUrl.indexOf("/join-free.aspx")!=-1 || currentUrl.indexOf("/membership.aspx")!=-1 ){
	    document.getElementById("navBuyNow").className += "active";
	}
	if ( currentUrl.indexOf("sign-in")!=-1 ){
	    document.getElementById("navLogin").className += "active";
	}
	if ( currentUrl.indexOf("playing-by-hits")!=-1 ){
	    document.getElementById("navBeginner").className += "active";
	}
	if ( currentUrl.indexOf("intermediate")!=-1 ){
	    document.getElementById("navIntermediate").className += "active";
	}
	if ( currentUrl.indexOf("drums")!=-1 ){
	    document.getElementById("navDrums").className += "active";
	}
	if (currentUrl.toLowerCase().indexOf("instructors") != -1) {
	    document.getElementById("navInstructors").className += "active";
	}
	if (currentUrl.indexOf("/buynow.aspx") != -1 ) {
	    document.getElementById("navBuy").className += "active";
	}
	/*
	if ( currentUrl.indexOf("support.aspx")!=-1 ){
	    document.getElementById("navSupport").className += "active";
	}
	*/
	if (document.getElementById("subnavigation") != null){	    
	    if ( document.getElementById("subnavigation").className !== "myacc"){
	        if ( document.getElementById("subnavigation").className == "about"){
			 if( document.getElementById("navAboutUs") != null)
	            	{
	            		document.getElementById("navAboutUs").className += "active";
			}
	        }
	        else  if ( document.getElementById("subnavigation").className == "support"){
			 if( document.getElementById("navSupport") != null)
		          {
	        		    document.getElementById("navSupport").className += "active";
			  }
	        }	    
	        else{
	            document.getElementById("navFreeLessons").className += "active";
	        }
	        var sfEls = document.getElementById("subnavigation").getElementsByTagName("LI");	    	        	    
	        for (var i=0; i<sfEls.length; i++) {
	            var currentClass = sfEls[i].className;	        
	            if ( currentClass.indexOf("last") != -1){	            
	                currentClass=currentClass.replace(new RegExp("last \\b"), "");
	            }	      	        
	            if (currentUrl.indexOf(currentClass)!=-1){
	                sfEls[i].className += " active";	            
	            }
	        }
        }	        
	}
	
	//Resize the left and right columns
	if ( document.getElementById("pageColumnLeft") ){
	    document.getElementById("pageColumnLeft").style.height = document.getElementById("pageWrapperInner").offsetHeight + "px";
	    document.getElementById("pageColumnRight").style.height = document.getElementById("pageWrapperInner").offsetHeight + "px";
	}
}

function ViewSystemRequirements(){    
   window.open('/system-requirements.aspx','SystemRequirements','scrollbars=yes,width=600,height=600');
}
function ViewLessonList(){    
   window.open('/lesson_list.aspx','LessonList','scrollbars=yes,width=600,height=600');
}

/*######################################################
Following code makes sure the update progress is 
displayed on any asynchronous call
######################################################*/
var prm;
var postBackElement;

function AssociateAjaxUiEvents()
{
    prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_initializeRequest(InitializeRequest);
    prm.add_endRequest(EndRequest);
}

function Cover(bottom, loadingBackground, elemToCenter, ignoreSize) {
    var elementLocation = Sys.UI.DomElement.getLocation(bottom);
    loadingBackground.style.position = 'absolute';
    loadingBackground.style.top = (elementLocation.y) + 'px';
    loadingBackground.style.left = (elementLocation.x) + 'px';
    
    //alert(elemToCenter.offsetHeight);
    
    var dimensions = Sys.UI.DomElement.getBounds(elemToCenter);
    elemToCenterHeight = 28/2;//dimensions.height/2;
    elemToCenterWidth = 92/2;//dimensions.width/2;
    
    //var offSetHeight = (bottom.offsetHeight/2) - (elemToCenter.offsetHeight/2) + 'px';
    //var offSetWidth = (bottom.offsetWidth/2) - (elemToCenter.offsetWidth/2) + 'px';
    
    var offSetHeight = (bottom.offsetHeight/2) - elemToCenterHeight + 'px';
    var offSetWidth = (bottom.offsetWidth/2) - elemToCenterWidth + 'px';
    
    if (!ignoreSize) {
        loadingBackground.style.height = bottom.offsetHeight + 'px';
        loadingBackground.style.width = bottom.offsetWidth + 'px';
    }
    if(elemToCenter){
        elemToCenter.style.left = offSetWidth;
        elemToCenter.style.top = offSetHeight;
        //alert(offSetHeight + ' ' + offSetWidth);
    }
}

function InitializeRequest(sender, args) {
    var ownerId = sender._postBackSettings.sourceElement.id;    
    var elementToOverlap = $get('contentWrapper');
    var elementLoadingBackground = $get('ajaxLoadingBackground');
    
    Cover(elementToOverlap, elementLoadingBackground, $get('ajaxLoadingMessage'));
    
    if (prm.get_isInAsyncPostBack()) {
        args.set_cancel(true);
    }
    postBackElement = args.get_postBackElement();
    $get('ajaxLoadingBackground').style.display = 'block';
}

function EndRequest(sender, args) {
    $get('ajaxLoadingBackground').style.display = 'none';
}

function pageLoad(){
    //Set parameters for ajax calls
    setTimeout('AssociateAjaxUiEvents()', 2000);
}

if(typeof(Sys) != 'undefined') Sys.Application.notifyScriptLoaded();

/*######################################################
End update progress display
######################################################*/
