function $(element) {
  return document.getElementById(element);
}



//------------------------------------------------------------
if( SagoolTv == undefined ){
	var SagoolTv = function(){}
}



//WINDOW
SagoolTv.Browser = {
	
	
	//WINDOW
	getWindowWidth:function(){
		if (parseInt(navigator.appVersion)>3) {
			if ( document.body.offsetWidth ){ // Gecko / WebKit
				return document.body.offsetWidth;
			} else if ( document.body.offsetWidth ){ // MS
				return document.body.offsetWidth;
			}
		}
	},

	getWindowHeight:function(){
		if (parseInt(navigator.appVersion)>3) {
			if ( document.body.offsetWidth ){ // Gecko / WebKit
				return document.body.offsetHeight;
			} else if ( document.body.offsetWidth ){ // MS
				return document.body.offsetHeight;
			}
		}
	}
}



//FLASH
SagoolTv.Flash = {
	/**
	* create sagoolTV Flash Object
	* @param    flashvars
	* @param    params
	* @param    attributes
	**/
	createFlashObject:function( flashvars , params , attributes ){

		var v = swfobject.getFlashPlayerVersion();
		if(v.major >= 9){
			$( "contentContainer" ).style.fontSize  = "0";
			$( "contentContainer" ).style.lineHeight = "1";
		}

	    if( flashvars == undefined || flashvars == null ){
	        flashvars = new Object();
	    }
		//FlashVars
	    flashvars._urchinVariables = escape( SagoolTv.Flash._getUrchinFlashVars() );
	    swfobject.embedSWF( "/swf/CoSagoolTv.swf?c=" + ( new Date() ).getTime() , "content", "100%", "100%", "9.0.0" , null , flashvars , params , attributes );
		swfmacmousewheel.registerObject(attributes.id);
	},
	
	
	/**
	* Wrapped get Urchin Variables
	* 
	**/
	_getUrchinFlashVars:function(page) {
	    var p,s="",pg=_udl.pathname+_udl.search;
	    if (page && page!="") pg=escape(page);
	    _ur=_ubd.referrer;
	    if (!_ur || _ur=="") { _ur="-"; }
	    else {
	        p=_ur.indexOf(_ubd.domain);
	        if ((p>=0) && (p<=8)) { _ur="0"; }
	        if (_ur.indexOf("[")==0 && _ur.lastIndexOf("]")==(_ur.length-1)) { _ur="-"; }
	    }
	    s+="&utmn="+_uu;
	    if (_ufsc) s+=_uBInfo(page);
	    if (_uctm && (!page || page=="")) s+=_uCInfo();
	    if (_utitle && _ubd.title && _ubd.title!="") s+="&utmdt="+escape(_ubd.title);
	    if (_udl.hostname && _udl.hostname!="") s+="&utmhn="+escape(_udl.hostname);
	    if (!page || page=="") s+="&utmr="+_ur;
	    s+="&utmp="+pg;
	    if (_userv==0 || _userv==2) {
	        return "utmwv="+_uwv+s;
	    }
	    if (_userv==1 || _userv==2) {
	        return "utmwv="+_uwv+s+"&utmac="+_uacct+"&utmcc="+_uGCS();
	    }
	    return;
	},
	
	
	/**
	* Resizing Flash Container
	* 
	**/
	updateScale:function(){
		var windowW = SagoolTv.Browser.getWindowWidth();
		var windowH = SagoolTv.Browser.getWindowHeight();
		var minW = 700;
		var minH = 450;
		var w,h;
		$( "contentContainer" ).style.width  = "100%";
		$( "contentContainer" ).style.height = "100%";
		return;
		// IE7
		if (typeof document.documentElement.style.msInterpolationMode != "undefined") {
			if( SagoolTv.ExternalInterface.isFullMode( windowW , windowH ) || (windowW >= minW && windowH >= minH)){
				w = "100%";
				h = "100%";
				document.body.scroll = "no";
			}else{
				w = Math.max( minW , (windowW) ) + "px";
				h = Math.max( minH , (windowH) ) + "px";
				document.body.scroll = "auto";
			}
		// other
		}else{
			if( SagoolTv.ExternalInterface.isFullMode( windowW , windowH ) ){
				w = ( windowW - 5 ) + "px";
				h = ( windowH - 5 ) + "px";
			}else{
				w = Math.max( minW , ( windowW - 5 ) ) + "px";
				h = Math.max( minH , ( windowH - 5 ) ) + "px";
			}
		}
		$( "contentContainer" ).style.width  = w;
		$( "contentContainer" ).style.height = h;
		/*
		var windowW = SagoolTv.Browser.getWindowWidth();
		var windowH = SagoolTv.Browser.getWindowHeight();
		if( SagoolTv.ExternalInterface.isFullMode() ){
			var w = ( windowW - 5 );
			var h = ( windowH - 5 );
		}else{
			var w = Math.max( 800 , ( windowW - 5 ) );
			var h = Math.max( 450 , ( windowH - 5 ) );
		}
		$( "contentContainer" ).style.width  = w + "px";
		$( "contentContainer" ).style.height = h + "px";
		*/
	}
}



//ExternalInterface
SagoolTv.ExternalInterface = {
    //_isFull:false,
    
    isFullMode:function(  windowW , windowH  ){
		if( windowW < 500 || windowH < 250 ){
			return true;
		}
        if( !$( "sagoolTvContent" ) ){
            return false;
        }
        if( !$( "sagoolTvContent" ).isModeFull ){
            return false;
        }
        return $( "sagoolTvContent" ).isModeFull();
    },
    
    
    NoticeSidebarFullModeChanged:function(){
        //SagoolTv.ExternalInterface._isFull = true;
        SagoolTv.Flash.updateScale();
    },
    
    
    NoticeSidebarNotFullModeChanged:function(){
        //SagoolTv.ExternalInterface._isFull = false;
        SagoolTv.Flash.updateScale();
    },
    
    
    urchinTracker:function(page){
        urchinTracker(page);
    }
}



window.onresize = function(){
	SagoolTv.Flash.updateScale();
    //alert( "#########" + $( "sagoolTvContent" ).isModeFull() );
}
