






    var videoPlayList = new Array();
    var nextURL = 0;
	var volume = 100;

	function moveToCenter(){
		var winWidth = $(window).width();
		var winHeight  = $(window).height();
		
		var oLeft = (winWidth - 880);
		var oTop = 0;
		
		if(oLeft<2){
			oLeft = 0;
		}else{
			oLeft = Math.ceil(oLeft/2) ;
		}
		
		
		
		$('#container img').css("position","absolute");
		$('#container img').css("left",oLeft+'px');
		$('#container img').css("top",oTop+'px');
		
		//$(this).css({'position' : 'absolute', 'font-weight' : 'bolder'});
		
		
		//$('#player').css("position","absolute");
		$('#player').css("left",(oLeft+65)+'px');
		$('#player').css("top",(oTop+100)+'px');
		
		 play();
		
		//alert(oLeft + '-' + oTop);
	}
    
    function getNextUrl(){
		nextURL = 1;
        var videoUrl = videoPlayList[Math.floor(Math.random()*videoPlayList.length)];
            
        $.get("flv_url.php", { url: videoUrl },
            function(data){
                nextURL = data;
                
                $.get(nextURL);
            }
        );

	}
    
    function play(){
        stop();
        
        if(nextURL == 0){
            nextURL = '105902906288_44011.mp4';
        }
        
        //alert(nextURL + 'çalınıyor...');
    
        //if (myListener.position == 0) {
            getFlashObject().SetVariable("method:setUrl", nextURL);
        //}
        getFlashObject().SetVariable("method:play", "");
        nextURL = 0;
    }

	function mute(){
		if(volume==0){
			volume = 100;
			getFlashObject().SetVariable("method:setVolume", volume);
		}else{
			volume = 0;
			getFlashObject().SetVariable("method:setVolume", volume);
		}
	}
	
	function fullscreen(){
		getFlashObject().SetVariable("method:toggleFullScreen", "");
	}
	
	



	var myListener = new Object();
	
	/**
	 * Initialisation
	 */
	myListener.onInit = function()
	{
		
	};
	/**
	 * onClick event on the video
	 */
	myListener.onClick = function()
	{
		var total = document.getElementById("info_click").innerHTML;
		document.getElementById("info_click").innerHTML = Number(total)+1;
	};
	/**
	 * onKeyUp event on the video
	 */
	myListener.onKeyUp = function(pKey)
	{
		document.getElementById("info_key").innerHTML = pKey;
	};
	/**
	 * onComplete event
	 */
	myListener.onFinished = function()
	{
		//alert("finished");
        play();
	};
	/**
	 * Update
	 */
	myListener.onUpdate = function()
	{
        var tmp = this.duration - 30000;
        
        if(this.position > tmp && nextURL == 0){
            getNextUrl();
        }
	};
	
	function getFlashObject()
	{
		return document.getElementById("myFlash");
	}
    
    function pause()
    {
        getFlashObject().SetVariable("method:pause", "");
    }
    function stop()
    {
        getFlashObject().SetVariable("method:stop", "");
    }
    function setWidth()
    {
    	var width = document.getElementById("inputWidth").value;
    	getFlashObject().width = width+"px";
    }
    function setHeight()
    {
    	var height = document.getElementById("inputHeight").value;
    	getFlashObject().height = height+"px";
    }
    function setPosition()
    {
    	var position = document.getElementById("inputPosition").value;
    	getFlashObject().SetVariable("method:setPosition", position);
    }
    function setVolume()
    {
    	var volume = document.getElementById("inputVolume").value;
    	getFlashObject().SetVariable("method:setVolume", volume);
    }
    function loadImage()
    {
    	var url = document.getElementById("inputImage").value;
    	var depth = document.getElementById("inputImageDepth").value;
    	var verticalAlign = document.getElementById("inputImageVertical").value;
    	var horizontalAlign = document.getElementById("inputImageHorizontal").value;
    	
    	getFlashObject().SetVariable("method:loadMovieOnTop", url+"|"+depth+"|"+verticalAlign+"|"+horizontalAlign);
    }
    function unloadImage()
    {
    	var depth = document.getElementById("inputUnloadDepth").value;
    	getFlashObject().SetVariable("method:unloadMovieOnTop", depth);
    }
    
    function showMyVideos(data) {
        var feed = data.feed;
        var entries = feed.entry || [];
        
        
        for (var i = 0; i < entries.length; i++) {
            var entry = entries[i];
            var title = entry['link'][0].href;
            
            videoPlayList.push(title);
            
            
        }
        
        
    }






google.setOnLoadCallback(function() {
	// BUTTONS
	$('.fg-button').hover(
		function(){ $(this).removeClass('ui-state-default').addClass('ui-state-focus'); },
		function(){ $(this).removeClass('ui-state-focus').addClass('ui-state-default'); }
	);
	
	// MENUS    	
	$('#flat').menu({ 
		content: $('#flat').next().html(), // grab content from this page
		showSpeed: 400 
	});
	
	play();
});