jQuery.noConflict();

(function($) {
  var cache = [];
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);

/**
 * IE detection
 * @returns true / false on IE or IE 6 detection
 * @type Boolean
 */
var isIE = /*@cc_on!@*/!1;
function ie6(){
	var strChUserAgent = navigator.userAgent;
	var intSplitStart = strChUserAgent.indexOf("(",0);
	var intSplitEnd = strChUserAgent.indexOf(")",0);
	var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);

	if(strChMid.indexOf("MSIE 6") != -1) return true;
	else return false;
}

var popup = function(link, width, height)
{
    window.open(link.href,'tools','menubar=1,location=1,resizable=1,scrollbars=1,status=1,width='+width+', height='+height);
    return false;
};


var stopVideo = function(){
	//alert("STOP VIDEO FNT");
	manageVideo("stop");
	//document.getElementById("flash").style.visibility = "hidden";
}
var restartVideo = function(){
	//alert("RESTART VIDEO FNT");
	manageVideo("start");
	//document.getElementById("flash").style.visibility = "visible";
}

var manageVideo = function(cmd){
	calleFlashMovie = document.getElementById("flash");
   calleFlashMovie.manageVideo(cmd);
}

var calltracking = function(ch_lang, ch_cat, ch_scat1)
{
    /*var _tag=new WebTrends();
    _tag.dcsGetId();*/

 
};

(function($) {
    $.kresize = {
        bind:false
    };
	$.fn.kresize = function(f)
	{
        if(!$.kresize.bind) {
            $.kresize.bind = true;
            var timeOut = 200;
            var to = false;
            $(window).resize(function() {
                if(to !== false)
                    clearTimeout(to);
                to = setTimeout(function(){$(window).triggerHandler('kresize')}, timeOut);
            });
        }
        this.each(function() {
            if(this == window) {
                $(this).bind('resize',f);
            }
        });
        return this;
    };
})(jQuery);

jQuery(document).ready(function($){

    var relUrl = '';
    if($('input[name="lang"]').length > 0) {
        relUrl = '../';
    }

    var cookieName = 'hp_lang';
    var pushCookie = function(lang)
    {
        var expDate = new Date();
        expDate.setTime(expDate.getTime() + (3650 * 24 * 3600 * 1000))
        document.cookie = cookieName + "=" + escape(lang) + ";expires=" + expDate.toGMTString() + ";path=/";
    }

    var getCookie = function()
    {
        deb = document.cookie.indexOf(cookieName + "=")
        if (deb >= 0)
        {
            deb += cookieName.length + 1
            fin = document.cookie.indexOf(";",deb)
            if (fin < 0) fin = document.cookie.length
            return unescape(document.cookie.substring(deb,fin))
        }
        return null;
    }

    var destroyCookie = function()
    {
        var expDate = new Date()
        expDate.setTime(expDate.getTime() + (-1 * 24 * 3600 * 1000));
        document.cookie = cookieName + "=" + escape('') + ";expires=" + expDate.toGMTString() + ";path=/";
    }

    var slideshowTime = 3000;
    //var animMinHeight = 300;
    //var animMaxHeight = 520;
    
    var animMinHeight = 350;
    var animMaxHeight = 800;
    var animRatio = 774/520;
    var slider_control = null;

    $('#flash').before('<iframe frameborder="0"></iframe>');
    var animHeight = 0;
    var resize = function() {

       if($.browser.msie && $.browser.version <= 6)
       {
           if($(window).width() < 960)
               $('.main').width(960);
           else
               $('.main').width('auto');
       }

       animHeight =  Math.min(Math.max($(window).height() - ($('.menu').outerHeight() + $('.footer').outerHeight()),animMinHeight),animMaxHeight);
       //animHeight =  animHeight + 100;
       $('.anim').height(animHeight);
       $('.anim iframe').height(animHeight);
       $('.anim #flash img').attr('height',animHeight);
       $('.anim #flash').attr('height',animHeight);
       
       animWidth = Math.round(animHeight * animRatio);
       $('.anim #flash').attr('width',animWidth);
     
       /*$('.main .specialmenu').css('width',(animWidth+2)+'px');
       $('.main .specialmenu').css('margin-left','-'+(animWidth+2)/2+'px');
       
       if(parseInt($('.main .specialmenu').css('height').substring(0,$('.main .specialmenu').css('height').indexOf('px', 0))) > 120 ){
    	   $('.main .specialmenu').css('height',(animHeight+30)+'px');
    	   $('.main .specialmenu .textbox').css('height',(animHeight-90)+'px');
    	   $('.main .specialmenu #slider').css('height',(animHeight-90)+'px');
    	       	   
    	   document.getElementById('textbox').scrollTop = 1;
    	   //alert(document.getElementById('textbox').scrollTop);
    	   if(document.getElementById('textbox').scrollTop == 0){
    		   $('.main .specialmenu #slider').hide();
    	   }else{
    		   $('.main .specialmenu #slider').show();
    	   }
    	   document.getElementById('textbox').scrollTop = 0;
    	   
    	   //$('.main .specialmenu').css('top','+='+animHeight+'px');
    	   slider_control.setDisabled();
    	   //if(document.getElementById('textbox')){
			slider_control = new Control.Slider('handle', 'slider', {
	        	axis: 'vertical',
	        	onSlide: function(value) {
					document.getElementById('textbox').scrollTop = Math.round(value/slider_control.maximum*(document.getElementById('textbox').scrollHeight-document.getElementById('textbox').offsetHeight));
	             },
	            onChange: function(value) {
	            	document.getElementById('textbox').scrollTop = Math.round(value/slider_control.maximum*(document.getElementById('textbox').scrollHeight-document.getElementById('textbox').offsetHeight));	
	            }
	        });
			//}
			slider_control.setEnabled();
       }*/
    }
    resize();

    var params = {
        wmode:"transparent",
        quality:"high",
        bgcolor:"#000000"
    };
    swfobject.embedSWF(relUrl+'swf/anim.swf', 'flash', animWidth, animHeight,'8.0.0',null, null,params);

        if($('.main .menu').length > 0) {
            var toM = null;
            $('.main .menu ul.lang>li:not(.ext)').mouseover(function(){
                clearTimeout(toM);
                if(!$(this).find('ul').hasClass('open')) {
                    $('.main .menu ul.lang li ul.open').stop();
                    $('.main .menu ul.lang li ul.open').css('height','auto');
                    $('.main .menu ul.lang li ul.open').hide().removeClass('open');
                    $(this).find('ul').addClass('open');
                    $(this).find('ul').css('left',- $(this).find('ul').parents('li').offset().left);
                    $(this).find('ul').css('padding-left',$(this).find('ul').parents('li').offset().left);
                    $(this).find('ul').width($(document.body).width() - $(this).find('ul').parents('li').offset().left-10);
                    var height = $(this).find('ul').height();
                    $(this).find('ul').height(0);
                    $(this).find('ul').show();
                    $(this).find('ul').animate({'height':height});
                    $(this).parents('ul').children('li').addClass('disable');
                    $(this).removeClass('disable');
                }
                return false;
            }).mouseout(function(){
                var ul = $(this).find('ul');
                toM = setTimeout(function(){
                    ul.stop(true,true);
                    ul.hide();
                    ul.css('height','auto');
                    ul.removeClass('open');
                    ul.parents('ul').find('li').removeClass('disable');
                }, 200);
            })
        
        }

 
        });

        

	


