$(document).ready(function() {
    //in master
                //initialize the slideshow when the DOM is ready
                $("#slideshow").css("width", "730px");
                $("#slideshow").css("height", "290px");
                $("#slideshow").css("display", "block");
                $('#slideshow').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 5000,
                                before:  slider_onBefore, 
                                after:   slider_onAfter
	});

	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		closePopup();
		e.stopPropagation();
	});

	$('.window').click(function (e) {
		e.stopPropagation();
	});

	//if mask is clicked
	//$('.mask').click(function () {
	//	closePopup();
	//});

	$('body').click(function () {
		closePopup();
	});

                
        //css for hover main menu
        $(".main-menu_folders li").hover(
            function () {
                $(".main-menu_folders li").each(function() {
                    if( $(this).hasClass("on_slider") ) {
                        $(this).removeClass("on_slider");
                        $(this).children().removeClass("on_slider");
                      }
                });
                $(this).addClass("hovered");
            },
            function () {
                on_slider_sync();
                if( $(this).hasClass("hovered") ) {
                    $(this).removeClass("hovered");
                }
            }
        );
});

function openPopup(id, focus) {
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('.mask').css({'width':maskWidth,'height':maskHeight});
    //$('.mask').css('display', 'block');

    //Set the popup window to center
    if( $(id).hasClass("centred") ) {
            //Get the window height and width
            var winH = $(window).height();
            var winW = $(window).width();
        var y = window.pageYOffset? window.pageYOffset: (document.body.scrollTop? document.body.scrollTop: 0);
        $(id).css('top',  winH/2-$(id).height()/2 + y);
        $(id).css('left', winW/2-$(id).width()/2);
    }
    //transition effect
    $(id).fadeIn(300);
    if(focus) {
            $(focus).focus();
    }
}

function closePopup() {
    $('.window:visible').trigger('closePopup');
    $('.mask').css('display', 'none');
    $('.window').hide();
}

function slider_onBefore() {
    $(".main-menu_folders li").each(function() {
            if( $(this).hasClass("on_slider") ) {
              $(this).removeClass("on_slider");
              $(this).children().removeClass("on_slider");
            }
    });
    var isHovered = $(".main-menu_folders li").hasClass("hovered");
    if(!isHovered) {
        var css_class = $(this).attr("class");
        if( css_class != null && css_class.length > 0 ) {
            $(".main-menu_folders ." + css_class ).children().addClass("on_slider");
            $(".main-menu_folders ." + css_class).addClass("on_slider");
        }
    }
}

function slider_onAfter() {
}

function on_slider_sync() {
        var css_class = $("#slideshow a:visible").attr("class");
        if( css_class != null && css_class.length > 0 ) {
                $(".main-menu_folders ." + css_class).children().addClass("on_slider");
                $(".main-menu_folders ." + css_class).addClass("on_slider");
        }
}

function bookmarksite(url, title) {
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if (window.opera && window.print) { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if (document.all)// ie
		window.external.AddFavorite(url, title);
	return false;
}

function sendpage(subject, body) {
  mail_str = "mailto:?subject= " + subject + document.title + "&body=" + body + document.location.href; 
  location.href = mail_str;
}

function confirmDeleteItem(lang) {
		var text = 'Your are about to delete this document. Do you want to proceed?';
		if(lang == 'de') { text = 'Soll die Datei jetzt wirklich aus der Mediathek entfernt werden?'; }
    return confirm(text);
}

