<!--

    ////////////////////////////////
    // Broadjam object
    ////////////////////////////////
    var broadjam = {
    	    
    	    initialize: function() {
    	        
    	        this.strCookieUserName = 'username';
    	        this.strCookiePasswordName = 'password';
    	        this.strCookieRememberName = 'remember';
    	        this.strCookieBjSessionIdName = 'BJPHPSESSID';
    	        
    	        
    	        this.strDevDomain = 'dev.broadjam.com';
    	        this.strDevRoot = '/bjam2';
	        this.strSkinName = 'broadjam2'; //remove the stinking hardCoding!
    	        this.setDefaultSkinDir = (document.location.host == this.strDevDomain) ? '/bjam2/assets/skins' + '/' + this.strSkinName  : '/assets/skins' + '/' + this.strSkinName;
    	        
    	        this.isDevEnvironment = function() {
                    return(document.location.host == this.strDevDomain);
                }
                
                this.setSkinAssets = function(strSkinAssetsDir) {
                    this.phpAssets = (strSkinAssetsDir == null) ? this.setDefaultSkinDir + '/php' : strSkinAssetsDir + '/js';
                    this.jsAssets = (strSkinAssetsDir == null) ? this.setDefaultSkinDir + '/js' : strSkinAssetsDir + '/js';
                }
                
                ////////////////////////////
                // window functions
                ////////////////////////////
                this.parentWindowLocation = function(strUrl) {
                    opener.location.href = strUrl;
                }
                
                this.detectPopupBlocker = function() {
                     var win = window.open('','','width=1,height=1,left=0,top=0,directories=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no');
                     if(win) {
                       win.close()
                       return false;
                     }
                     else
                        return true;
                }
                
                this.popUpWindow = function(strPage, strName, strScrollbar, strScrollbars, strResizable, intWidth, intHeight, intLeft, intTop) {
                    if(this.detectPopupBlocker())
                        alert("A popup blocker was detected. Please allow pop-up windows for broadjam.com.");
                    else {
                        var winOpts = "scrollbar=" + strScrollbar + ",scrollbars=" + strScrollbars + ",menubar=no,resizable=" + strResizable + ",width=" + intWidth + ",height=" + intHeight + ",left=" + intLeft + ",top=" + intTop;
                
                        var popWin = window.open(strPage, strName, winOpts);
                        if (popWin.focus)
                		      popWin.focus();
                    }
                    return;
                }
                
                // functions pulled from old newWindows.js
                this.openNewWindow = function(url, windowName, args) {
                    win = window.open(url, windowName, args);
                    if(parseInt(navigator.appVersion) >= 4) {
                        win.focus();
                    }
                    return win;
                }
                
                ////////////////////////////
                // layer functions
                ////////////////////////////
                this.toggleLayer = function(whichLayer) {
                	if (document.getElementById)
                	{
                		// this is the way the standards work
                		var divStyle = document.getElementById(whichLayer).style;
                	}
                	else if (document.all)
                	{
                		// this is the way old msie versions work
                		var divStyle = document.all[whichLayer].style;
                	}
                	else if (document.layers)
                	{
                		// this is the way nn4 works
                		var divStyle = document.layers[whichLayer].style;
                	}
                	
                	divStyle.display = (divStyle.display == 'none')? 'block':'none';
                }
                
                this.showLayer = function(whichLayer) {
                    if (document.getElementById)
                	{
                		// this is the way the standards work
                		var divStyle = document.getElementById(whichLayer).style;
                	}
                	else if (document.all)
                	{
                		// this is the way old msie versions work
                		var divStyle = document.all[whichLayer].style;
                	}
                	else if (document.layers)
                	{
                		// this is the way nn4 works
                		var divStyle = document.layers[whichLayer].style;
                	}
                	
                	divStyle.display = 'block';
                }
                
                this.hideLayer = function(whichLayer) {
                    if (document.getElementById)
                	{
                		// this is the way the standards work
                		var divStyle = document.getElementById(whichLayer).style;
                	}
                	else if (document.all)
                	{
                		// this is the way old msie versions work
                		var divStyle = document.all[whichLayer].style;
                	}
                	else if (document.layers)
                	{
                		// this is the way nn4 works
                		var divStyle = document.layers[whichLayer].style;
                	}
                	
                	divStyle.display = 'none';
                }

                ///////////////////////////
    	        // Add all required javascript files
    	        // dynamically
    	        ///////////////////////////
    	        this.addJavascript = function(strJsName) {
                    var th = document.getElementsByTagName('head')[0];
                    var s = document.createElement('script');
                    s.setAttribute('type','text/javascript');
                    s.setAttribute('src',strJsName); 
                    th.appendChild(s);
                }
                 
                this.posWaitIcon = function() {
                	strAppName = navigator.appVersion;
                	if(navigator.appName == 'Microsoft Internet Explorer' && strAppName.indexOf('MSIE 7.0') != -1) {
                		if(document.getElementById('elmWaitIconHolder')) {
                			var elmObj = document.getElementById('elmWaitIconHolder');
                			var leftPos = (document.documentElement.clientWidth/2)-50 + 'px';
                			var topPos = (document.documentElement.clientHeight/2)-50 + 'px';
                			elmObj.style.left = leftPos;
                			elmObj.style.top = topPos;
                		}
                	} else {
                		if(navigator.appName == 'Microsoft Internet Explorer' && strAppName.indexOf('MSIE 6.0') != -1) {
                			if(document.getElementById('elmWaitIconHolder')) {
                				var elmObj = document.getElementById('elmWaitIcon_ctl');
                				var leftPos = (document.body.clientWidth/2)-50 + 'px';
                				var topPos = (document.body.clientHeight/2)-50 + 'px';
                				elmObj.style.left = leftPos;
                				elmObj.style.top = topPos;
                			}
                		} else {
                			if(document.getElementById('elmWaitIconHolder')) {
                				var elmObj = document.getElementById('elmWaitIconHolder');
                				var leftPos = (window.innerWidth/2)-50 + 'px';
                				var topPos = (window.innerHeight/2)-50 + 'px';
                				elmObj.style.left = leftPos;
                				elmObj.style.top = topPos;
                			}
                		}
                	}
                }
                
                this.getCookie = function(strName) {
                    // this fixes an issue with the old method, ambiguous values 
                    // with this test document.cookie.indexOf( name + "=" );
                	// first we'll split this cookie up into name/value pairs
                	// note: document.cookie only returns name=value, not the other components
                	var arAllCookies = document.cookie.split( ';' );
                	var arTempCookie = '';
                	var strCookieName = '';
                	var strCookieValue = '';
                	var blnCookieFound = false; // set boolean t/f default f
                	
                	for ( i = 0; i < arAllCookies.length; i++ )
                	{
                		// now we'll split apart each name=value pair
                		arTempCookie = arAllCookies[i].split( '=' );

                		// and trim left/right whitespace while we're at it
                		strCookieName = arTempCookie[0].replace(/^\s+|\s+$/g, '');
                		
                		// if the extracted name matches passed check_name
                		if ( strCookieName == strName )
                		{
                			blnCookieFound = true;
                			// we need to handle case where cookie has no value but exists (no = sign, that is):
                			if ( arTempCookie.length > 1 )
                			{
                				strCookieValue = unescape( arTempCookie[1].replace(/^\s+|\s+$/g, '') );
                			}
                			
                			// note that in cases where cookie is initialized but no value, null is returned
                			return strCookieValue;
                			break;
                		}
                		arTempCookie = null;
                		strCookieName = '';
                	}
                	if ( !blnCookieFound )
                	{
                		return null;
                	}
                }
                
                this.deleteCookie = function(strName, strPath, strDomain) {
                    
                    if(strPath == null) {
                        strPath = (this.isDevEnvironment())? this.strDevRoot : '/';
                    }
                    
                    if(strDomain == null) {
                        strDomain = document.location.host;
                    }
                    
                    if ( this.getCookie( strName ) ) {
				document.cookie = strName + "=" +
                    		( ( strPath ) ? ";path=" + strPath : "") +
                    		( ( strDomain ) ? ";domain=" + strDomain : "" ) +
                    		";expires=Thu, 01-Jan-1970 00:00:01 GMT";

			      // remove he broad-er broadjam.com cookie
				strDomain = "broadjam.com";

				document.cookie = strName + "=" +
                    		( ( strPath ) ? ";path=" + strPath : "") +
                    		( ( strDomain ) ? ";domain=" + strDomain : "" ) +
                    		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
			  }

                }
                
                this.setCookie = function( strName, strValue, intExpireDays, strPath, strDomain, secure ) {
                    
                    if(strPath == null) {
                        strPath = (this.isDevEnvironment())? this.strDevRoot : '/';
                    }
                    // set time, it's in milliseconds
                    var today = new Date();
                    today.setTime( today.getTime() );
                    
                    /*
                    if the expires variable is set, make the correct 
                    expires time, the current script below will set 
                    it for x number of days, to make it for hours, 
                    delete * 24, for minutes, delete * 60 * 24
                    */
                    if ( intExpireDays )
                    {
                        intExpireDays = intExpireDays * 1000 * 60 * 60 * 24;
                    }
                    var dtExpires = new Date( today.getTime() + (intExpireDays) );
                    
                    document.cookie = strName + "=" +escape( strValue ) +
                    ( ( intExpireDays ) ? ";expires=" + dtExpires.toGMTString() : "" ) + 
                    ( ( strPath ) ? ";path=" + strPath : "" ) + 
                    ( ( strDomain ) ? ";domain=" + strDomain : "" ) +
                    ( ( secure ) ? ";secure" : "" );
                }
                
                this.logout = function() {
                    // delete all the cookies
                    this.deleteCookie(this.strCookieUserName);
                    this.deleteCookie(this.strCookiePasswordName);
                    this.deleteCookie(this.strCookieRememberName);
                    this.deleteCookie(this.strCookieBjSessionIdName);
                    
                    // refreash the page
                    var strUrl = document.location.protocol + '//' + document.location.host;
                    strUrl += (this.isDevEnvironment())? this.strDevRoot + '/index.php' : '/index.php';
                    this.refresh(strUrl);
                    
                }
                
                this.refresh = function(strURL) {
                    
                    //window.location.reload( false );
                    window.location.href = (strURL) ? unescape(strURL) : unescape(window.location.pathname);

                }
                
                
                /////////////////////////
                // Online functionality
                /////////////////////////
                // if we have a bjConn object then call online now
                this.onlineCk = function() {
                    if (typeof bjConn != "undefined") {
                        bjConn.strOnlineAJAXHandler = document.location.protocol + '//' + document.location.hostname + this.phpAssets + '/connections/online.php';
                        bjConn.online();
                    } 
                }
                
                
                /////////////////////////
                // Urchin functionality
                /////////////////////////
                this.trackPageView = function(strPageName) {
                    if(window.urchinTracker) {
                        urchinTracker(strPageName);
                    }
                }
                
            } // end of initialize
    };
    
    ////////////////////////////////
    // Broadjam object Shortcut and Initialize
    ////////////////////////////////
    var bj = broadjam;
    bj.initialize();
    bj.setSkinAssets();
    bj.onlineCk();
	
////////////////////////////////
// @todo migrate all functions into the broadjam(bj) object
////////////////////////////////
function _isDevEnvironment() {
    return bj.isDevEnvironment();
}

function toggleLayer(whichLayer) {
	bj.toggleLayer(whichLayer);
}

function showLayer(whichLayer) {
    bj.showLayer(whichLayer);
}

function hideLayer(whichLayer) {
    bj.hideLayer(whichLayer);
}

function __pop_up(strPage, strName, strScrollbar, strScrollbars, strResizable, intWidth, intHeight, intLeft, intTop) {
	bj.popUpWindow(strPage, strName, strScrollbar, strScrollbars, strResizable, intWidth, intHeight, intLeft, intTop);
}

function __pop_up_media_player(strPage) {
	bj.popUpWindow(strPage, "Player", 'no','no','no', 586, 274, 100, 250);
}

function __pop_up_video_player(strPage) {
	bj.popUpWindow(strPage, "Player", 'no','no','no', 320, 260, 100, 250);
}

function __pop_up_debug(strPage) {
	bj.popUpWindow(strPage, "Debug", 'no','no','yes', 300, 450, 100, 250);
}

function __pop_up_add_to_shoppingcart(strPage) {
    bj.popUpWindow(strPage, "AddToShoppingCart", 'no','no','no', 300, 300, 100, 250);
}

function __popup_add_to_medialist(strPage) {
    bj.popUpWindow(strPage, 'AddToPlaylist', 'yes','yes','no', 390, 690, 100, 250);
}

function __popup_add_favorite_artist(strPage) {
    bj.popUpWindow(strPage, 'AddToFavorites', 'no','no','no', 300, 300, 100, 250);
}

function posWaitIcon() {
	bj.posWaitIcon();
}

function parentWindowLocation(strUrl) {
    bj.parentWindowLocation(strUrl);
}

// interface for tracking pages. 
// call this if using AJAX
function trackPageView(strPageName) {
    bj.trackPageView(strPageName);
}

// functions pulled from ols newWindows.js
function OpenNewWindow(url, windowName, args) {
    bj.openNewWindow(url, windowName, args);
}

function OpenNewWindow2(url,winwidth,winheight) {
   bj.openNewWindow(url,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,scrollbars=no,resizable=no,copyhistory=no,width='+winwidth+',height='+winheight);
}

function OpenNewWindow3(url,winwidth,winheight) {
    bj.openNewWindow(url,'addtofavorites','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,scrollbars=no,resizable=no,copyhistory=no,width='+winwidth+',height='+winheight);
}

function OpenNewWindowMediaLists(url,winwidth,winheight) {
    bj.openNewWindow(url,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,scrollbars=yes,resizable=no,copyhistory=no,width='+winwidth+',height='+winheight);
}

function OpenNewWindow2(url,winwidth,winheight) {
    bj.openNewWindow(url,'FAQ','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,scrollbars=no,resizable=no,copyhistory=no,width='+winwidth+',height='+winheight);
}

function NewWindow(mypage,myname,w,h,scroll) {
    var winl = (screen.width-w)/2;
    var wint = (screen.height-h)/2;
    var scroll = (scroll == null) ? 'no' : scroll;
    var settings ='height='+h+',';
    settings +='width='+w+',';
    settings +='top='+wint+',';
    settings +='left='+winl+',';
    settings +='scrollbars='+scroll+',';
    settings +='resizable=no';
    
    bj.openNewWindow(mypage, myname, settings);
}
 
function MM_openBrWindow(theURL,winName,features) { 
     bj.openNewWindow(theURL,winName,features);
}

function textHintHandler(strControlId, strAction, strColor, strHint) {
	//alert(strControlId + '; ' + strAction + '; ' + strColor + '; ' + strHint);
	if(strAction == 'focus') {
		if(document.getElementById(strControlId).value == '' || document.getElementById(strControlId).value == strHint + ' ') {
			document.getElementById(strControlId).value = '';
			document.getElementById(strControlId).style.color = strColor;
		}
	}
	if(strAction == 'blur') {
		if(document.getElementById(strControlId).value == '') {
			document.getElementById(strControlId).value = strHint + ' ';
			document.getElementById(strControlId).style.color = strColor;
		}
	}
}

//-->
