function basename (path, suffix) {
// Returns the filename component of the path  
// 
// version: 1004.2314
// discuss at: http://phpjs.org/functions/basename    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// +   improved by: Ash Searle (http://hexmen.com/blog/)
// +   improved by: Lincoln Ramsay
// +   improved by: djmix
// *     example 1: basename('/www/site/home.htm', '.htm');    // *     returns 1: 'home'
// *     example 2: basename('ecra.php?p=1');
// *     returns 2: 'ecra.php?p=1'
var b = path.replace(/^.*[\/\\]/g, '');
	if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
	b = b.substr(0, b.length-suffix.length);
}
return b;
}
var chromeMenu=1;	
var sImageObject;
var menuHovers = new Array();
menuHovers[0] = "menu1_active.png";
menuHovers[1] = "menu2_active.png";
menuHovers[2] = "menu3_active.png";
menuHovers[3] = "menu4_active.png";
menuHovers[4] = "menu6_active.png";
menuHovers[5] = "menu5_active.png";
menuHovers[6] = "menu7_active.png";
menuHovers[7] = "menu8_active.png";

function slowMenuImageAppear(vIndex){
		var imgObject=$("#menuhead_" + vIndex + " a img")[0];
		imgObject.src=imgObject.src.replace("_active","");
	}
	
	function getActiveHeaderMenuIndex(){
		checkPage=location.href;
		checkPage=checkPage.toLowerCase();
		clientLoginPage="ClientArea.aspx";
		clientLoginPage=clientLoginPage.toLowerCase();
		
		if( checkPage.indexOf(clientLoginPage)>=0){
			return 6;
		}
		for(j=0;j<headerMenuIds.length;j++){
			if(headerMenuIds[j]==PageRootMenuId){
				return j;
			}	
		}
	}
	
	function changeImageSrc(mIndex,mMode){
			var curMenuIndex= parseInt(getActiveHeaderMenuIndex() + 1);
			
			if(curMenuIndex==mIndex) return;
			var imgObject=$("#menuhead_" + mIndex + " a img")[0];
			if(imgObject!=null){
			var replaceChar=basename(imgObject.src);
			if(mMode==1)
				replaceVal=menuHovers[mIndex-1].replace("_active","v");	
			else
				replaceVal=menuHovers[mIndex-1].replace("_active","");
			imgObject.src=imgObject.src.replace(replaceChar,replaceVal);
			}
	}
function initializeHeaderMenu(){
	if($.browser.msie && $.browser.version<=6.0)
	{return;
	}
	$("#chromemenu li").hover(
	  function () {
	  	
		var menuIndex=parseInt(this.id.replace("menuhead_",""));
		var imgObject=$("#menuhead_" + menuIndex + " a img")[0];
		if(basename(imgObject.src).indexOf("menu8")>=0)  menuIndex=menuIndex+1;
		var replaceChar=basename(imgObject.src);
		imgObject.src=imgObject.src.replace(replaceChar,menuHovers[menuIndex-1]);
		changeImageSrc(menuIndex-1,1);
		
		if(menuIndex==3) 
			$(".menuLeftLevel0").css("width","115px");
		else
			$(".menuLeftLevel0").css("width","auto");
	  }, 
	  function () {
	  	var curMenuIndex=getActiveHeaderMenuIndex() + 1;
		var menuIndex=parseInt(this.id.replace("menuhead_",""));
		var imgObject=$("#menuhead_" + menuIndex + " a img")[0];
		if(curMenuIndex!=menuIndex){
				setTimeout("slowMenuImageAppear(" + menuIndex + ")",100);
		}else{
			if(curMenuIndex==7){
			
			}else
			{
			imgObject.src=imgObject.src.replace("_active","_activep");
			}
		}
		changeImageSrc(menuIndex-1,0);
		activateHeaderMenu();
	  }
	);
	
	
}

function activateHeaderMenu(){

	var menuIndex= parseInt(getActiveHeaderMenuIndex() + 1);
	var imgObject=$("#menuhead_" + menuIndex + " a img")[0];
	if(imgObject!=null){
	
	if(menuIndex==7)
		imgObject.src=imgObject.src.replace(basename(imgObject.src),menuHovers[menuIndex-1].replace("_active","_active"));
	else{
		imgObject.src=imgObject.src.replace(basename(imgObject.src),menuHovers[menuIndex-1].replace("_active","_activep"));
		
	}
	changeImageSrc(menuIndex-1,1);
		
	}
}

$(document).ready(function() {
    formatMenuTitle();
    if ($.browser.msie && $.browser.version <= 6.0) {
        $(".dropmenudiv").hide();
        return;
    }

    if ($.browser.msie && $.browser.version <= 8.0) {
        $(".dropmenudiv").css("margin-top", "-5");
    }

    if (navigator.userAgent.toLowerCase().indexOf('chrome/12.0') >= 0) {
        $(".dropmenudiv").css("margin-top", "35px");
    }


    if ($("#ctl01_divCenter").html() != null) {
        var vContent = jQuery.trim($("#ctl01_divCenter").html());

        if (vContent.length == 0) {
            location.href = "VRXHome.aspx";

        }
    }

    if (chromeMenu == 1) {
        if (typeof (cssdropdown) != "undefined")
            cssdropdown.startchrome("chromemenu");

    }

    var userAgent = navigator.userAgent.toString().toLowerCase();
    if ((userAgent.indexOf('safari') != -1) && !(userAgent.indexOf('chrome') != -1)) {
        if (userAgent.indexOf('version/4.0') != -1) {
            $('#dvSafariCSS').html('');
        } else {
            $('#dvSafari4CSS').html('');
        }
    } else {
        $('#dvSafariCSS').html('');
        $('#dvSafari4CSS').html('');
    }

    //if(!($.browser.safari)){
    $("input[id*='VRXSettingsSubPageBottomContentId']").attr("readonly", "readonly");
    bindModalPopLinks();
    initializeAdminMenu();

});

function initializeAdminMenu(){

$("#adminLoginLink a").each(function(v){
	this.href=AdminLoginUrl;
	this.innerHTML="Admin Logout";
	if(LoginStatus==0){
		this.innerHTML="Admin Login";
	}
});

}
function bindModalPopLinks(){
    $("a").each(function() {

        var contentIds = this.href.split('=');
        var modId = 0;

        if (this.href.indexOf('modal=1') > 0 && this.href.indexOf('AjaxHandler') <= -1) {
            this.title = "";
            var modalWidth = $.urlParam(this.href, 'w');
            var modalHeight = $.urlParam(this.href, 'h');
            var modalScrollbar = $.urlParam(this.href, 'scroll');
            this.target = "_blank";
            var kSettings = { width: modalWidth, height: modalHeight, endFillContent: function(p1, p2) { removeScrollForModalPopUp(modalScrollbar); } };
            $(this).nyroModal(kSettings);
        }

        modId = $.urlParam(this.href, 'pid');
        if (contentIds.length > 0 && modId > 0 && this.href.indexOf('Edit') < 0) {
            footerParam = $.urlParam(this.href, 'ftr');
            fixedHeight = $.urlParam(this.href, 'fh');

            this.href = baseSitePath + "/AjaxHandler.ashx?modal=1&title=" + this.title + "&mid=" + modId + "&ftr=" + footerParam;
            this.title = "";
            this.target = "";
            var kSettings;
            var resizeWin = true;
            var vHeight = null;
            if (fixedHeight == 1) vHeight = 684;
            if ($.browser.msie && $.browser.version == "7.0") resizeWin = false;
            if (footerParam == 1)
                kSettings = { windowResize: resizeWin, height: vHeight, width: 951, endFillContent: function(p1, p2) { applyScrollingForPopUp(0); },
                    endShowContent: function(p1, p2) {
                        if (vHeight == null) {
                            $("#popContText").height(p2.height - 202);
                            $('.content').css('overflow', 'auto');
                            $('.content').jScrollPane({ showArrows: true });
                        }
                    },
                    resize: function(p1, p2) { if (vHeight == null) { $("#nyroModalContent").width(p2.width); $("#popContText").height(p2.height - 202); } }
                };
            else
                kSettings = { windowResize: resizeWin, width: 951, height: vHeight,
                    resize: function(p1, p2) {
                        if (vHeight == null)
                            $("#nyroModalContent").width(p2.width); $("#popContText").height(p2.height - 78);
                    },
                    endShowContent: function(p1, p2) {
                        if (vHeight == null) {
                            $("#popContText").height(p2.height - 78);
                            $('.content').css('overflow', 'auto');
                            $('.content').jScrollPane({ showArrows: true });
                        }
                        else {
                            $("#popContText").css("max-height", p2.height - 78);
                            $('.content').css('overflow', 'auto');
                            $('.content').jScrollPane({ showArrows: true });
                        }
                    },
                    endFillContent: function(p1, p2) { applyScrollingForPopUp(0); }
                };


            $(this).nyroModal(kSettings);
        }

    });
}

function attachReturnKey(vTextObjectName,vButtonObjectName){
		$("#" +vTextObjectName).keyup(function(evt){
			if (evt.which || evt.keyCode){
			if ((evt.which == 13) || (evt.keyCode == 13))
								$("#" +vButtonObjectName).click();
			}
		});
}

function applyCustomModalParams(vItemName) {
			var winHeight= $(window).height();
            $("." + vItemName + " a").each(function() {
				this.title="";
                var paramVal = '{' + this.rel.replace(/=/gi, ':') + '}';
				
                var actualParams = eval('(' + paramVal + ')');
                if (this.className == 'extwin') {
                } else if (this.className == 'intwin') {
                    this.target = "";
                } else {
					var checkFileName='VTGallery.aspx';
					checkFileName=checkFileName.toLowerCase();
					var actualLinkName=this.href.toLowerCase();
					
					if(actualLinkName.indexOf(checkFileName)>0){
						
                    	this.target="_blank";		
                        this.title = "";
                        
						 var kSettings = { width: actualParams.width, height: actualParams.height };
						 linkTitle=$("#" + this.id + " img").attr("title");
						 imgPositions=linkTitle.split('#');
						 thumbIndex=parseInt(imgPositions[1]);
						if(imgPositions.length>1 && thumbIndex>=1)
							this.href = this.href + "&w=" + actualParams.width + "&h=" + actualParams.height + "&showindex=" + thumbIndex;
						else
							this.href = this.href + "&w=" + actualParams.width + "&h=" + actualParams.height + "&showindex=" + thumbIndex;
							
						$(this).nyroModal(kSettings);
                    }
                    else if (actualParams.scroll == 0) {
						
						if(winHeight<=700 && $.browser.msie && vItemName!="brochurelist"){
							$(this).unbind('click.nyroModal');
							$(this).click(function(e){
							e.preventDefault();
							var resizableProp=",resizable=0";
							
							winWidth=$.urlParam(this.href,'width');
							winHeight=$.urlParam(this.href,'height');
							if(winWidth==""){
							winWidth="100";
							winHeight="100";
							resizableProp=",resizable=1";
							}
							window.open(this.href,"","top=50%,left=50%,width="+ winWidth + ",height=" + winHeight + resizableProp);
							});
							
						}else{
							var kSettings = { width: actualParams.width, height: actualParams.height, endFillContent: function(p1, p2) { applyScrollingForPopUp(0); } };
							$(this).nyroModal(kSettings);
						}

                    } else if (actualParams.scroll == 1) {
						if(winHeight<=700 && $.browser.msie && vItemName!="brochurelist"){
							$(this).unbind('click.nyroModal');
							$(this).click(function(e){
							e.preventDefault();
							var resizableProp=",resizable=0";
							
							winWidth=$.urlParam(this.href,'width');
							winHeight=$.urlParam(this.href,'height');
							if(winWidth==""){
							winWidth="100";
							winHeight="100";
							resizableProp=",resizable=1";
							}
							window.open(this.href,"","top=50%,left=50%,width="+ winWidth + ",height=" + winHeight + resizableProp);
							
							});
						}else{	
                        var kSettings = { width: actualParams.width, height: actualParams.height, endFillContent: function(p1, p2) { applyScrollingForPopUp(1); } };
                        $(this).nyroModal(kSettings);
						}
                    }

                }

            });
}

function removeScrollForModalPopUp(vMode){
vMode=parseInt(vMode)

if(vMode==-1){

	$("div#nyroModalContent").css("overflow", "hidden");
	$("#nyroModalIframe").attr("scrolling", "no");

}

}
function applyScrollingForPopUp(scrollMode) {
    if (scrollMode == 0)
        $("div#nyroModalContent").css("overflow", "hidden");
    else 
        $("div#nyroModalContent").css("overflow", "auto");		
}
		
function OpenTargetBannerUrl(vUrlLink){
			var winBHeight= $(window).height();
			var modalWidth = $.urlParam(vUrlLink,'w');
			var isNewPop=1;
				if(vUrlLink.indexOf('modal=1')>0){
					var modalWidth = $.urlParam(vUrlLink,'w');
					var modalHeight = $.urlParam(vUrlLink,'h');
					if(modalWidth>0){	
						isNewPop=0;
						if(winBHeight<=700 && $.browser.msie ){
							var resizableProp=",resizable=1";
							winWidth=modalWidth;
							winHeight=modalHeight;
							window.open(vUrlLink,"","top=50%,left=50%,width="+ winWidth + ",height=" + winHeight + resizableProp);
														
						}else{
							$.nyroModalManual({
							url: vUrlLink,
							width:modalWidth,
							height:modalHeight
							});
						}
					}					
				}
				if(isNewPop==1){
				
					var modalWidth = $.urlParam(vUrlLink,'width');
					var modalHeight = $.urlParam(vUrlLink,'height');
					if(modalWidth>0)
						window.open(vUrlLink,"","scrollbars=0,toolbars=0,menubars=0,width="+ modalWidth +",height=" + modalHeight+ ",top=50%,left=50%");
					else
						window.open(vUrlLink);

				}
			
		}
		
	$.urlParam = function(vUrl,paramName){
	var results = new RegExp('[\\?&]' + paramName + '=([^&#]*)').exec(vUrl);
	if (!results) { return 0; }
	return results[1] || 0;}


if (navigator.userAgent.indexOf("MSIE 6.0")>0 && navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent && navigator.userAgent.indexOf("Opera")==-1)
{	

	window.attachEvent("onload", LoadPng);
}


function LoadPng()
{
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--)
	{
		if (itsAllGood && img.src.match(/\.png$/i) != null)
		{
			var src = img.src;
			img.style.width = img.width + "px";
			img.style.height = img.height + "px";
			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
			img.src = "images/1px.gif";
		}
		img.style.visibility = "visible";
	}
	
	$("#wrapcenter").css("margin-top","-21");

}

function formatMenuTitle(){

$("#dropmenu6 a").each(function(vItem){

	var linktext=this.innerHTML;
		if(linktext.indexOf('Clients Say')>=0)
			this.innerHTML=linktext.replace(/Clients/gi, '<br/>&nbsp;&nbsp;&nbsp;&nbsp;Clients');
		//$(this).html(linktext.replace(/  /gi, '<br/>&nbsp;&nbsp;&nbsp;&nbsp;'));
	
	});

}
