﻿$(document).ready(function () {
    //http://fancybox.net
    $("a.fancyboxSingle").fancybox({
        'showCloseButton':true,
        'autoScale': true,
        'type': 'image'
    });

    //http://fancybox.net
    $("a.fancyboxVideo").fancybox({
        'width': 440,
        'height':320,
        'showCloseButton': true,
        'autoScale': false,
        'type': 'iframe'
    });

    //http://fancybox.net
    $(".MediaPlaner a").fancybox({
        'width': 980,
        'height': 620,
        'showCloseButton': true,
        'autoScale': false,
        'type': 'iframe'
    });

    accordion("#accordion h2");
    accordion("#accordionHauptdaten h3");
    jqLanguages();
    jqMainNav();

    hlGalleryRotatorCreate(1400, 4000); //DurationFade,DurationLoop 
});

function writeTeaserFlash(divname, filename) {
    var fo = new FlashObject(filename, "flashGallery", "516", "155", "8.0.15", "#333333", true);
    fo.write(divname);
}


function accordion(strSelButton, strSelArea) {
    $(strSelButton).next().hide();
    $(strSelButton + ":first").next().show();

    $(strSelButton).mousedown(function () {
        $(this).next().slideToggle(500, function () {

        });
    });
}

/*Language Comboboxes*/
var g_cbLangTimeout = null;
function jqLanguages() {
    $("#CBLanguagesContainer").mouseenter(function () {
        cbFadeIn("#CBLanguages");
    });
    $("#CBLanguagesContainer").click(function () {
        cbFadeIn("#CBLanguages");
    });
    $("#CBLanguagesContainer").mouseleave(function () {
        cbFadeOut("#CBLanguages");
    });
    $("#CBLanguagesContainer LI a").fadeTo(0,0.6);
    $("#CBLanguagesContainer LI").mouseenter(function(){
        $(this).children("a").fadeTo(200,1);
    });
    $("#CBLanguagesContainer LI").mouseleave(function(){
        $(this).children("a").fadeTo(200,0.6);       
    });
}
function cbFadeIn(strSelector) {
    if (g_cbLangTimeout != null) {
        window.clearTimeout(g_cbLangTimeout);
    }
    $(strSelector).fadeIn(250, function(){});
}
function cbFadeOut(strSelector) {
    g_cbLangTimeout = window.setTimeout(function(){$(strSelector).fadeOut(250);},500);
}
/*navigation*/
function jqMainNav() {
    $(".liMainNav").mouseenter(function () {
        $(this).children(".divMainNavSubContainer").fadeIn(250);
    });
    $(".liMainNav").mouseleave(function () {
        $(this).children(".divMainNavSubContainer").fadeOut(250);
    });
}

/*Gallery*/
var _hlGalleryIndexCurrent = undefined;
var _hlGalleryIndexLast = 0;
var _hlGalleryAltIndexCurrent = 0;
var _hlGalleryAltMouseOffset = 20;
var _hlGalleryLoopTO = null;
var _hlGalleryQueueTO = null;
var _hlGalleryRestartLoopTO = null;
var _hlGalleryInAnimation = false;
var _hlGalleryLoopStoped = false;
var _hlGalleryDurationFade = 500;
var _hlGalleryDurationLoop = 5000;

function hlGalleryQueue(iIndex) {
    if (_hlGalleryQueueTO != null) { window.clearTimeout(_hlGalleryQueueTO); }
    if (_hlGalleryInAnimation) {
        window.setTimeout("hlGalleryQueue(" + iIndex + ")", 50);
    } else {
        hlGalleryLoop(iIndex);
    }
}

function hlGalleryLoop(iIndex) {
    if (_hlGalleryLoopTO != null) { window.clearTimeout(_hlGalleryLoopTO); }
    if (iIndex > _hlGalleryIndexLast) { iIndex = 0; }
    if (iIndex != _hlGalleryIndexCurrent && !_hlGalleryInAnimation) {
        hlGalleryFadeIn(iIndex);
        if (_hlGalleryIndexCurrent != undefined) {
            hlGalleryFadeOut(_hlGalleryIndexCurrent);
        }
        _hlGalleryIndexCurrent = iIndex;
    }
    if (!_hlGalleryLoopStoped) {
        _hlGalleryLoopTO = window.setTimeout("hlGalleryLoop(" + (iIndex + 1) + ")", _hlGalleryDurationLoop);
    }
}

function hlGalleryRotatorCreate(DurationFade, DurationLoop) {
    _hlGalleryDurationFade = DurationFade;
    _hlGalleryDurationLoop = DurationLoop;

    _hlGalleryIndexLast = $("div.galleryItem").length - 1;

    hlGalleryLoop(0);
}

function hlGalleryFadeOut(iIndex) {
    var strBannerWidth = $("div.sstRotatorContainer").css("width");
    //initial state
    $("div.galleryItem:eq(" + iIndex + ") .galleryImage").show();
    $("div.galleryItem:eq(" + iIndex + ") .galleryImage").fadeOut(_hlGalleryDurationFade);
    $("div.galleryItem:eq(" + iIndex + ") .galleryImage").css({ marginLeft: '0px' });

}
function hlGalleryFadeIn(iIndex) {
    _hlGalleryInAnimation = true;
    
    var strBannerWidth = $("div.galleryCanvas").css("width");
    //initial state
    $("div.galleryItem:eq(" + iIndex + ")").css({ display: "block" });
    $("div.galleryItem:eq(" + iIndex + ") .galleryImage").hide(); //opacity: 0.0
    $("div.galleryItem:eq(" + iIndex + ") .galleryImage").fadeIn(_hlGalleryDurationFade, function () { _hlGalleryInAnimation = false; });
   
}

function Debugger(strVal) {
    var oDebuger = document.getElementById("txtDebug");
    if (oDebuger != null) {
        oDebuger.value += "\n" + strVal;
    }
}

var g_strSearchText="SUCHE";
function searchFocus(){
	var oInput=document.getElementById("LayoutSearchInput");
	if(oInput!=null){
		if(oInput.value==g_strSearchText){
			oInput.value="";
			oInput.style.color="#000000";
		}
	}
}
function searchBlur(){
	var oInput=document.getElementById("LayoutSearchInput");
	if(oInput!=null){
		if(oInput.value==""){
			oInput.value=g_strSearchText;
			oInput.style.color="#878787";
		}
	}
}

