// avoid problems with Firebug console missing
if(typeof console == 'undefined') console = new Object();

$(document).ready(function(){

    ieTitle=document.title; // Backup the document title for IE

    $('ul#menu a'). click(function(e){
        update_menu_highlights(e);
        var t=e.target;
        var txt=$(t).text();
        var elements=$(t).siblings('ul');
        if(txt[0]=='>'||txt[1]=='>'||txt.charAt(0)=='>'||txt.charAt(1)=='>') load_content(e);

        if(!elements||elements.length==0) return;

        elements.slideToggle(200);


        var rest=txt.substring(1, txt.length);
        if(txt.slice(0, 1)=='-') {
            $(t).text('+'+rest);
        }
        else{
            $(t).text('-'+rest);
        }
    });

    $('ul#menu *').disableTextSelect();

    $('div.right').empty();

    var fv=function(data){
        $('#videos').html(data);
    }
    if(!document.location.hash||document.location.hash.length<2){
    $.get("startvisual.php", {
        lang: langi
    },fv);
    }else if(document.location.hash.substring(1,3)=='v:'){
  var str=document.location.hash.substring(3)
  playvideo(str);
    }else{
  var arr=document.getElementsByTagName('a');
  var e;
  var str=document.location.hash.substring(1)
  str=str.replace(/%20/gi, " ")
  for(var v in arr){
      if($(arr[v]).attr('rel')==str){
    e=arr[v];
    break;
      }
  }
  load_content({target:e},str);
        $(e).parents('li').children('ul').css('display','block');
    }


    if (show!="") playvideo(show);

});



/**
 * 2009.07.28
 * Actual AJAX loader for menu item
 */
function load_content(e,address) {
    if(!address){
        var t=e.target;
  address = $(t).attr('rel');
    }
    $('#videos').empty();
    $.get("get_content.php", {
        address: address,
        lang: langi
    },
    function(data){
        $('#videos').html(data);
    });
    update_menu_highlights(e);
}





/**
 * 2009.07.28
 * Updates CSS classes for menu elements
 * based on which one is active.
 * Sets class 'actual'
 */
function update_menu_highlights(e)
{
    var t=e.target;
    $('ul#menu a').removeClass('actual');
    $(t).addClass('actual');
    $(t).parents('li').children('a').addClass('actual');
}

function recommend(videofile){
    var isFull=!!document.getElementById('playerobject');
    videofile=videofile?videofile:document.location.hash.substring(1);
    $('#recommend_box').empty();
    $.get("recommend.php",{
  lang: langi,
  f:'form',
  full:isFull,
  videofile:document.location.protocol+"//"+document.location.hostname+document.location.pathname+document.location.search+'#'+videofile
    },function(data){
  $('#recommend_box').html(data);
	if(device != ("iPad" || "iPhone")) {
    		recommendResize(isFull);
	}else{
		MediaElement("player1", {success: function(me) {
			me.pause();
		}});
		if(orient == "portrait"){
			$("#jquery-overlay").css("width", "1024px");
			$("#recommend_box").css("width", "768px");
		}
	}
    });
}

function sendRecommend(){
    var isFull=document.getElementById('full').value;
    var o={
  lang: langi,
  f:'send',
  iName:document.getElementById('iName').value,
  iEmail:document.getElementById('iEmail').value,
  eEmail:document.getElementById('eEmail').value,
  videofile:document.getElementById('videofile').value,
  txt:document.getElementById('txt').value,
  chk:document.getElementById('chk').checked,
  full:isFull
    }
    $('#recommend_box').empty();
    $.get("recommend.php",o,function(data){
  $('#recommend_box').html(data);
  recommendResize(isFull);
    });
}
function recommendResize(isFull){
    if(!!document.getElementById('recommendWidthContainer')&&!!document.getElementById('playerobject')){
        setTimeout(function(){
      resizePlayerWindow();
  },1);
    }
}

function nextvid (nextvidurl) {
    document.location.hash="#v:"+nextvidurl;
    playvideo(nextvidurl);
}
function lastvid (lastvidurl) {
    document.location.hash="#v:"+lastvidurl;
    playvideo(lastvidurl);
}

function close() {
  removeOverlay();
}

function setPath(t) {
  $('#pathTitle').text(t);
}

function showInfo(){
  $('#description_layer p').text(infotext);
  $('#description_layer').slideToggle();
}



   

