/*!
 * LiberoVision Website JavaScript Library 
 * http://www.liberovision.com/
 *
 * Copyright (c) 2009 Christoph Niederberger
 *
 * Date: 2009-06-15
 */
 
		$(function() {
		    
		    // menu animation and ajax load
			var $klapp = $('#div-navigation li.categories li');
			$klapp.filter(':not(.current-cat)').children('ul').css("display","none");
			$klapp.filter(':has(ul)').children(':first-child').append(' <img src="images/news_marker.png">').click(
				function()
				{
					$(this).parent().siblings().children('ul:visible').slideUp('normal');
					$(this).parent().parent().siblings().children().children('ul:visible').slideUp('normal');
					$(this).next().slideToggle('normal');
                    ajaxify($(this).attr('id'), false);		
					return false;
				}
			);               

            // menu item (withot child) click -> ajax
            $(".cat-item").click(function() {
                ajaxify($(this).children('a').attr('id'), false);
                return false;
            });
            
            // sub item (child) click -> ajax
            $(".cat-sub-item").click(function() {
                ajaxify($(this).attr('id'), false);
                return false;
            });

            // main item click -> ajax
            $(".main-item").click(function() {
                ajaxify($(this).attr('id'), false);
                return false;
            });
                        
            // link color of menu
            $('a').click(function() {
                //alert('test');
                // all read
                $('a').removeClass('current');
                // clicked black
                $(this).addClass('current');
            });
                        
            // load if hash is set
            $(function() {
                //alert('load');
                if (window.location.href.indexOf('#')!=-1)
                {
                    ajaxify(window.location.hash.substr(1), false);
                }
                $_name = $('#div-flash').attr('name');
                $('#div-flash').append(put_flash($_name));                
            });
      
      function put_flash(id)
      {      
        return AC_FL_RunContent(
        'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
        'width', '480',
        'height', '270',
        'src', 'movies/' + id,
        'quality', 'high',
        'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
        'align', 'middle',
        'play', 'true',
        'loop', 'true',
        'scale', 'showall',
        'wmode', 'window',
        'devicefont', 'false',
        'id', id,
        'bgcolor', '#ffffff',
        'name', 'LV_DE_3Dplus',
        'menu', 'true',
        'allowFullScreen', 'false',
        'allowScriptAccess','sameDomain',
        'movie', 'movies/' + id,
        'salign', ''
        );
    };

    function ajaxify(file, fadeout)
    {
        if (fadeout)
        {
            $.get("getContent.php?t=" + file,function(data) {
                $("#div-content").fadeOut('normal',function()
                {
                    //window.location.hash = file;
                    $(this).html(data).fadeIn('normal');
                    $_name = $('#div-flash').attr('name');
                    $('#div-flash').append(put_flash($_name));
                    //$.get("getTitle.php?t=" + file, function(data) { document.title = "LiberoVision - " + data; });
                });
            });
        } else {
            $.get("getContent.php?t=" + file,function(data) {
                // load content to div and set hash
                $("#div-content").html(data).fadeIn();
                // window.location.hash = file;
                // handle flash
                $_name = $('#div-flash').attr('name');
                $('#div-flash').append(put_flash($_name));
                // set title
                //$.get("getTitle.php?t=" + file, function(data) { document.title = "LiberoVision - " + data; });
            });
        }
    }

});

function createXHR() 
{
    var request = false;
        try {
            request = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (err2) {
            try {
                request = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (err3) {
		try {
			request = new XMLHttpRequest();
		}
		catch (err1) 
		{
			request = false;
		}
            }
        }
    return request;
}

function loadContent()
{
    var xhr = createXHR();
    xhr.onreadystatechange  = function()
        { 
             if(xhr.readyState  == 4)
             {
                  if(xhr.status  == 200) 
                      document.getElementById("div-content").innertHTML = "Received:"  + xhr.responseText; 
                  else 
                     document.getElementById("div-content").innertHTML = "AJAX Error code " + xhr.status;
             }
        }; 

   xhr.open(GET, "main.0.content",  false); 
   //xhr.open(GET, "getContent.php?l=0&m=1&s=1",  false); 
   xhr.send(null); 
}