window.onload=function(){
	
	// check for galleries to autostart
	var qs = new Querystring() ;
	var v1 = qs.get('lb', false) ;
	
	if (v1 != false)
	{
		setTimeout('startLB(\'' + v1 + '\')', 100);
	}
	
	
	
	// fix google toolbar for IE
	if (window.attachEvent)
	{
		setListeners() ;
	}
	
	//Nifty("ul#nav a","small top");
	//Nifty("div.wrap","small bottom");
	//Nifty("div.wrap-bl","small bl");
	
	
	if (typeof Control != 'undefined' ) 
	{
			initScrollbars() ; // scrollbar
		
			if ( getCookie("play_scroll_position") && getCookie("play_scroll_position") != 'null')
			{
				scrollers['scroll-box-1'].slider.setValue( getCookie("play_scroll_position") ) ;
				
				setCookie("play_scroll_position", 'null');
			}
	}
	
	startList() ;
}


startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("pn");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}


function startLB(img_id)
{
	var lb = new Lightbox();
	lb.start( document.getElementById(img_id) );
}


function setListeners(){
    inputList = document.getElementsByTagName("INPUT");
    for(i=0;i<inputList.length;i++){
        inputList[i].attachEvent("onpropertychange",restoreStyles);
        inputList[i].style.backgroundColor = "";
    }
    selectList = document.getElementsByTagName("SELECT");
    for(i=0;i<selectList.length;i++){
        selectList[i].attachEvent("onpropertychange",restoreStyles);
        selectList[i].style.backgroundColor = "";
    }
}

function restoreStyles(){
    if(event.srcElement.style.backgroundColor != "")
        event.srcElement.style.backgroundColor = "";
}


function sendFeedback()
{	
	location.href = 'mailto:feedback@bodog.tv?subject=BodogTV Beta Feedback' ;
}

function contactBodog()
{	
	location.href = 'mailto:service@bodog.com?subject=BodogFIGHT' ;
}

function open_red_devils()
{
	var new_window = window.open("fighters/red-devils.html",null, "status=yes,scrollbars=yes,toolbar=no,menubar=no,location=no");
}

function tvPolicy()
{
	var new_window = window.open("files/privacy-policy.html",null, "height=600,width=750,status=yes,scrollbars=yes,toolbar=no,menubar=no,location=no");
}

function open_rules()
{
	var new_window = window.open("files/bf-rules-reg.html",null, "height=600,width=750,status=yes,scrollbars=yes,toolbar=no,menubar=no,location=no");
}

function open_privacy_policy()
{
	var new_window = window.open("files/bf-privacy-policy.html",null, "height=470,width=750,status=yes,scrollbars=yes,toolbar=no,menubar=no,location=no");
}

/***** Added by JunHo ******/

function full_screen_mode(video_id, time)
{
	var fullscreen = window.open( "/fullscreen/?watch="+video_id+"&time="+time,
		   "FullScreenVideo", "toolbar=no,width=640,height=505,status=no,resizable=yes,scrollbars=no");
  
	if(fullscreen) {
		fullscreen.focus();
	} else {
		var popUpsBlocked = true;
		toggle_msg('popup_error_msg');
	}
	
}

function toggle_msg(id)
{
	var q = document.getElementById(id);
	if (q.style.display == "none") { 
		document.getElementById(id).style.display = "";
	} else {
		document.getElementById(id).style.display = "none";
	}
}

/*	Original
function full_screen_mode(video_id, time)
{
  var fullscreen = window.open( "/fullscreen/?watch="+video_id+"&time="+time,
		   "FullScreenVideo", "toolbar=no,width=640,height=505,status=no,resizable=yes,scrollbars=no");
  fullscreen.focus();
}
*/



function rollover_playlist_item( li_element )
{
	
	var img_src = li_element.style.backgroundImage ;
	var img_split = img_src.split("-off") ;
	
	if ( img_split.length == 1 )
	{
		img_split = img_src.split("-on") ;
		li_element.style.backgroundImage = img_split[0] + '-off' + img_split[1] ;
	}
	else
	{
		li_element.style.backgroundImage = img_split[0] + '-on' + img_split[1] ;
	}	
	
}


function rollover( e )
{
	var img_src = e.childNodes[0].src ;
	var img_split = img_src.split("-off") ;
	
	if ( img_split.length == 1 )
	{
		img_split = img_src.split("-on") ;
		e.childNodes[0].src = img_split[0] + '-off' + img_split[1] ;
	}
	else
	{
		e.childNodes[0].src = img_split[0] + '-on' + img_split[1] ;
	}
}





var scrollers = new Object() ;
scrollers['scroll-box-1'] = new Object() ; // Use this one for recording the scroll on page reload
scrollers['scroll-box-2'] = new Object() ; // extra
scrollers['scroll-box-3'] = new Object() ; // extra

scrollers['scroll-box-1'].current_value = 0 ;
scrollers['scroll-box-2'].current_value = 0 ;
scrollers['scroll-box-3'].current_value = 0 ;


function initScrollbars()
{
	
	if ( document.getElementById('scroll-box-1') )
	{
		scrollers['scroll-box-1'].slider = new Control.Slider('handle-1','track-1',{axis:'vertical',
		onSlide:function(v){scrollPlaylist(v, 'scroll-box-1')},
		onChange:function(v){scrollPlaylist(v, 'scroll-box-1')}}
		);
	}
	
	if ( document.getElementById('scroll-box-2') )
	{
		scrollers['scroll-box-2'].slider = new Control.Slider('handle-2','track-2',{axis:'vertical',
		onSlide:function(v){scrollPlaylist(v, 'scroll-box-2')},
		onChange:function(v){scrollPlaylist(v, 'scroll-box-2')}}
		);
	}
	
	if ( document.getElementById('scroll-box-3') )
	{
		scrollers['scroll-box-3'].slider = new Control.Slider('handle-3','track-3',{axis:'vertical',
		onSlide:function(v){scrollPlaylist(v, 'scroll-box-3')},
		onChange:function(v){scrollPlaylist(v, 'scroll-box-3')}}
		);
	}

	/**
	/* FIX FOR NO :HOVER IN IE6 ON DIVs
	*/
	
	if (document.all)
	{
	
		if ( document.getElementById('handle-1') )
		{
					var de = document.getElementById('handle-1') ;
					
					de.onmouseover = function()
					{
						this.className+= " scrollbarHandleOver" ;
					}
					
					de.onmouseout = function()
					{
						this.className=this.className.replace("scrollbarHandleOver", "");
					}
		}


		if ( document.getElementById('handle-2') )
		{
					var de = document.getElementById('handle-2') ;
					
					de.onmouseover = function()
					{
						this.className+= " scrollbarHandleOver" ;
					}
					
					de.onmouseout = function()
					{
						this.className=this.className.replace("scrollbarHandleOver", "");
					}
		}

		if ( document.getElementById('handle-3') )
		{
					var de = document.getElementById('handle-3') ;
					
					de.onmouseover = function()
					{
						this.className+= " scrollbarHandleOver" ;
					}
					
					de.onmouseout = function()
					{
						this.className=this.className.replace("scrollbarHandleOver", "");
					}
		}

	} // end if

} // end func

function scroll_down( target, speed )
{
	
	var new_value = scrollers[target].current_value+speed ;
	if (new_value > 1)
	{
		scrollers[target].current_value = 1 ;
	}
	else
	{
		scrollers[target].slider.setValue(new_value) ;
	}
	
}

function scroll_up( target, speed )
{
	var new_value = scrollers[target].current_value-speed ;
	if (new_value < 0)
	{
		scrollers[target].current_value = 0 ;
	}
	else
	{
		scrollers[target].slider.setValue(new_value) ;
	}
}


function scrollPlaylist(pct, e)
{
	pct = Math.round(pct*100)/100;
	
	scrollers[e].current_value = pct ;
	var height = document.getElementById(e).scrollHeight - document.getElementById(e).clientHeight ;
	document.getElementById(e).scrollTop = height * pct ;
	

}

function saveScrollPosition()
{
	setCookie("play_scroll_position", scrollers['scroll-box-1'].current_value ) ;
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


