﻿function writeYTBlue() {
	$('#ytPlayers').html('<div id="ytBlue">&nbsp;</div>');
	var params = { allowScriptAccess: "always" };
	var atts = { id: "ytBlue" };
	swfobject.embedSWF("http://www.youtube.com/v/pZ7h9x1spTQ&amp;border=0&amp;enablejsapi=1&amp;playerapiid=ytplayerBlue&amp;hl=en&amp;fs=1&amp;autoplay=1", "ytBlue", "416", "335", "8", null, null, params, atts);
	//swfobject.embedSWF("http://www.youtube.com/v/pZ7h9x1spTQ&amp;border=0&amp;enablejsapi=1&amp;playerapiid=ytplayerBlue&amp;ap=%2526fmt%3D18", "ytBlue", "416", "335", "8", null, null, params, atts);
}

function writeYTRed() {
	$('#ytPlayers').html('<div id="ytRed">&nbsp;</div>');
	var params = { allowScriptAccess: "always" };
	var atts = { id: "ytRed" };
	swfobject.embedSWF("http://www.youtube.com/v/yNWzUEYuVlE&amp;border=0&amp;enablejsapi=1&amp;playerapiid=ytplayerRed&amp;hl=en&amp;fs=1", "ytRed", "416", "335", "8", null, null, params, atts);
	//swfobject.embedSWF("http://www.youtube.com/v/yNWzUEYuVlE&amp;border=0&amp;enablejsapi=1&amp;playerapiid=ytplayerRed&amp;ap=%2526fmt%3D18", "ytRed", "416", "335", "8", null, null, params, atts);
}

$(function(){
	// center scroll
	window.scrollTo( (( $('#all').width() - $(window).width())/2)-20 , 0)

    // reWrite link blank class
    $('a.blank').attr('target','_blank');
    // Hidden Link
    //$('a[@href=#]').attr('href','javascript:void(0);');
    
	// BROWSER HACKS
	// adjust go 4 ie & ff
	
	if($.browser.safari)
		$('head link[@href$=style.css]').clone().attr('href', $('head link[@href$=style.css]').attr('href').replace('style.css','safari.css')).appendTo('head');
	
    // AutoText Search
    $('input.textSearch').val(($('input.textSearch').val()=="")?'Type Keywords':$('input.textSearch').val());
    $('input.textSearch')
        .focus(function(){
            if( $(this).val() == 'Type Keywords' ) {
                $(this).val('');
		$(this).css('color','#666');
            }
        })
        .blur(function(){
            if( $(this).val().length < 1 ) {
                $(this).val('Type Keywords');
		$(this).css('color','#999');
            }
        });
    
	// current-cat
	//if($('li.current-cat').length <1)
	//	$('li.all').addClass('current-cat');
	// currentCat = (document.location.search.match('cat=([0-9]*)'))? document.location.search.match('cat=([0-9]*)')[1] : 0;
	// $('li.cat-item-'+currentCat).addClass('current-cat');
		
		
	
    // Alternate video HD - 3D
    $('#ytRed').hide();
    
	$('#watchTitle a.red').click(function(){
        $('body').attr('id','red');
		$('.blue').show();
		$('.red').hide();
		
		writeYTRed();

		// $('#ytRed').show();
		// $('#ytBlue').hide();
		
		$('#downloadVideo a.red').show();
		$('#downloadVideo a.blue').hide();
    });
    
	$('#watchTitle a.blue').click(function(){
        $('body').attr('id','blue');
        $('.blue').hide();
		$('.red').show();
		
		writeYTBlue();
		// $('#ytRed').hide();
		// $('#ytBlue').show();
		
		$('#downloadVideo a.red').hide();
		$('#downloadVideo a.blue').show();
    });
    
	
	// max 1660
	
    // reWrite heights
    $('img').ready(function(){
		altura = $('#posts').height();
		$('.blocksLeft').height(eval(altura-10));
		$('.blocksRight').height(eval(altura-10));
		if($.browser.mozilla)
			$('#all').height(eval(altura+812));
		else
			$('#all').height(eval(altura+797));
	});
    
    // API youtube
    function updateHTML(elmId, value) {
          document.getElementById(elmId).innerHTML = value;
        }

        function setytplayerState(newState) {
          updateHTML("playerstate", newState);
        }

        function onYouTubePlayerReady(playerId) {
          ytplayer = document.getElementById("myytplayer");
          setInterval(updateytplayerInfo, 250);
          updateytplayerInfo();
          ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
          ytplayer.addEventListener("onError", "onPlayerError");
        }

        function onytplayerStateChange(newState) {
          setytplayerState(newState);
        }

        function onPlayerError(errorCode) {
          alert("An error occurred: "+ errorCode);
        }

        function updateytplayerInfo() {
          updateHTML("bytesloaded", getBytesLoaded());
          updateHTML("bytestotal", getBytesTotal());
          updateHTML("videoduration", getDuration());
          updateHTML("videotime", getCurrentTime());
          updateHTML("startbytes", getStartBytes());
        }

        // functions for the api calls
        function play() {
          if (ytplayer) {
            ytplayer.playVideo();
          }
        }

        function pause() {
          if (ytplayer) {
            ytplayer.pauseVideo();
          }
        }

        function stop() {
          if (ytplayer) {
            ytplayer.stopVideo();
          }
        }

        function getPlayerState() {
          if (ytplayer) {
            return ytplayer.getPlayerState();
          }
        }

        function seekTo(seconds) {
          if (ytplayer) {
            ytplayer.seekTo(seconds, true);
          }
        }

        function getBytesLoaded() {
          if (ytplayer) {
            return ytplayer.getVideoBytesLoaded();
          }
        }

        function getBytesTotal() {
          if (ytplayer) {
            return ytplayer.getVideoBytesTotal();
          }
        }

        function getCurrentTime() {
          if (ytplayer) {
            return ytplayer.getCurrentTime();
          }
        }

        function getDuration() {
          if (ytplayer) {
            return ytplayer.getDuration();
          }
        }

        function getStartBytes() {
          if (ytplayer) {
            return ytplayer.getVideoStartBytes();
          }
        }

        function mute() {
          if (ytplayer) {
            ytplayer.mute();
          }
        }

        function unMute() {
          if (ytplayer) {
            ytplayer.unMute();
          }
        }
		
	// TVs pos-load
	//writeYTBlue();
});

window.onload = function() {
	writeYTBlue();
}

