/**
 * Uhlsport default.js
 * -------------------------------------------------------------------------
 * @author Weitclick
 * @copyright Copyright(C) 2009, Weitcklick
 * @version $Id: default.js 22 2009-02-23 13:52:40Z ma $
 * @revision $LastChangedRevision:0 $
 **/

/* : GLOBALS : */
var strLastOpenBigBreadNav = '';
var startingHight = 0;
var direction = '';
var modifikation = 0;

/* : FUNKTIONEN : */
function InitAll() {
	if($.browser.name == "msie") {
		fixButtonsIE();
	}
	
	$('a').click(function() {
		this.blur();
	});

	$.ifixpng('/fileadmin/templates/img/shared/transpix.gif');
	$('img[rel="fixpng"]').ifixpng();
	$('dt>img').ifixpng(); 
	
	if(FlashResizer.headerType == 'headonly') {
		modifikation = 0;
		$('#text-teaser>.text-teaser_item').css('padding-top', '23px');
	} else {
		modifikation = 24;
		
		if($('#breadnav').length > 0) {
			$('#main').css('top', '62px');
		}
	}

	$('div#text-teaser').height(65-modifikation);
	
	$('div#text-teaser').bind('click',function(){
		toggleTeaser();
	});
	
	$('div.teaserOpen').bind('click',function(){
		toggleTeaser();
	});
	
	$('div.teaserClose').bind('click',function(){
		toggleTeaser();
	});
	
	resizeMainDiv();
	
	if($('#main').height() < ($('#main').attr('scrollHeight') - $('#main').css('padding-top').replace(/px/, ''))) {
		$('#logo').css('right', '20px');
		$('#nav_buttons').css('margin-right', '150px');
		if($('div.go').length > 0) {
			$('div.go').css('margin-left', '11px');
		}
	} else {
		$('#logo').css('right', '10px');
		$('#nav_buttons').css('margin-right', '140px');
		if($('div.go').length > 0) {
			$('div.go').css('margin-left', '21px');
		}
	}
	
	if($.browser.name == "firefox" && $.browser.versionNumber == "2") {
		$('div#breadnav').css('z-index','0');
	}
	
	if($.browser.name == "firefox" && $.browser.versionNumber == "3") {
		$('#nav_buttons>a>button>div').css('line-height','1px');
		$('button').css('padding-bottom','5px');
	}
	
	if ($.browser.name == 'msie' && $.browser.versionNumber == '6') {
		$('div#breadnav').css('background', 'url(fileadmin/templates/img/shared/breadCrump_zu.gif) left bottom no-repeat');
	}
}

function ShowPop(element) {
	document.getElementById(element).style.display='block';
}

function HiddenPop(element) {
	document.getElementById(element).style.display='none';
}

function toggleTeaser()
{
	if ($('div#text-teaser').height() == 65-modifikation) {
		$('div.teaserOpen').hide();
		direction = 'up';
		gotoHeight = 197-modifikation;
		$('#text-teaser').css('right', '0px');
		$('div#text-teaser').animate({ "height": gotoHeight }, 'slow', function(){
			if (($.browser.name == 'msie' && $.browser.versionNumber == '6') && (FlashResizer.wmodetransparent == 0 && FlashResizer.scaleFlash == 1)) {
				var higher = (startingHight - $('#text-teaser').height()) + 60-modifikation;
				$('#teaserflash>embed').attr('height', higher);
				$('#teaserflash').height(higher);
				$('#main').height(higher);
			}
		
			$('div.teaserClose').show();
		});
	} else {
		$('div.teaserClose').hide();
		direction = 'down';
		gotoHeight = 65-modifikation;
		$('div#text-teaser').animate({ "height": gotoHeight }, 'slow', function(){
			if(($.browser.name == 'msie' && $.browser.versionNumber == '6') && (FlashResizer.wmodetransparent == 0 && FlashResizer.scaleFlash == 1)) {
				var higher = (startingHight-$('#text-teaser').height()) + 60-modifikation;
				$('#teaserflash>embed').attr('height',higher);
				$('#teaserflash').height(higher);
				$('#main').height(higher);
			}
		
			$('div.teaserOpen').show();
			$('#text-teaser').css('right', '17px');
		});
	}
}

function clickTeaserLink(link) {
	$('div#text-teaser').unbind();
	window.location = link;	
}

var default_pos_main = 32; // aus main.css
var default_pos_main_offset = 0;
var resize1st = true;

function resizeMainDiv()
{
	if(isFullFlash) { // Wenn komplett Flash dann keine Anpassung
		$('#text-teaser').css('right', 0);
		if ($('#breadnav').length > 0) {
			$('#main').height(($(window).height() - default_pos_main_offset) - 130);
		}
	} else {
		if(resize1st) {
			// die Standard-Position aus der main.css wird abgezogen,
			// der Wert hat somit 0 - ausser bei einer weiteren CSS-Anpassung
			// wird der Wert geändert, z.B. Abstand im Finder.
			// Die Differenz wird auch von der main_height abgezogen.
			default_pos_main_offset = $('#main').css('top').replace(/px/, '') - default_pos_main;
			resize1st = false;
		}
		new_main_top = default_pos_main_offset;
		new_main_height = $(window).height() - default_pos_main_offset;
				
		if($('#nav_main').height()) {
			var navmain_offset = 8; // Feinanpassung sichtbarer Bereich
			new_main_height -= ($('#nav_main').height() - navmain_offset);
			new_main_top += ($('#nav_main').height() - navmain_offset);
		}
		
		if($('#breadnav').height()) {
			var breadnav_offset = 4; // Feinanpassung sichtbarer Bereich
			new_main_height -= ($('#breadnav').height() - breadnav_offset);
			new_main_top += ($('#breadnav').height() - breadnav_offset);
		}
		
		if($('#text-teaser').height()) {
			new_main_height -= ($('#text-teaser').height() - 25); // Offset weil sichtbarer Element-Bereich kleiner
		}		
		
		if($('#footer').height()) {
			new_main_height -= $('#footer').height();
		}

		$('#main').height(new_main_height);
		$('#main').css('top', new_main_top);
		$('#main').css('padding', 0);
	}
	
	FlashResizer.resize();
}

/* : EVENTS : */
$(window).resize(function(){
	if (FlashResizer.scaleFlash == 1 && FlashResizer.wmodetransparent == 0) {
		FlashResizer.maxHeight = ($(window).height() - 103);
		FlashResizer.minHeight = ($(window).height() - 103);
	}
	
	resizeMainDiv();
	
	if($('#main').height() < ($('#main').attr('scrollHeight') - $('#main').css('padding-top').replace(/px/, ''))) {
		$('#logo').css('right', '20px');
		$('#nav_buttons').css('margin-right', '130px');
		if($('div.go').length > 0) {
			$('div.go').css('margin-left', '11px');
		}
	} else {
		$('#logo').css('right', '10px');
		$('#nav_buttons').css('margin-right', '120px');
		if($('div.go').length > 0) {
			$('div.go').css('margin-left', '21px');
		}
	}
});



function include( filename ) {
    // http://kevin.vanzonneveld.net
    // +   original by: mdsjack (http://www.mdsjack.bo.it)
    // +   improved by: Legaev Andrey
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Michael White (http://getsprink.com)
    // %        note 1: Force Javascript execution to pause until the file is loaded. Usually causes failure if the file never loads. ( Use sparingly! )
    // %        note 2: The included file does not come available until a second script block, so typically use this in the header.
    // *     example 1: include('http://www.phpjs.org/js/phpjs/_supporters/pj_test_supportfile_2.js');
    // *     returns 1: 1
 
    var js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', filename);
    js.setAttribute('defer', 'defer');
    document.getElementsByTagName('HEAD')[0].appendChild(js);
 
    // save include state for reference by include_once
    var cur_file = {};
    cur_file[window.location.href] = 1;
 
    if (!window.php_js) window.php_js = {};
    if (!window.php_js.includes) window.php_js.includes = cur_file;
    if (!window.php_js.includes[filename]) {
        window.php_js.includes[filename] = 1;
    } else {
        window.php_js.includes[filename]++;
    }
 
    return window.php_js.includes[filename];
}

function fixButtonsIE()
{
	var objButtonList	= $('a>button');

	objButtonList.each(function(i){
		if($(this).parent().attr('href') != 'javascript:void(0);' && $(this).parent().attr('href') != 'undefined') {
			$(this).bind('click', function(){
				window.location = $(this).parent().attr('href');
			});
		}
	});
}

function include_once( filename ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Legaev Andrey
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Michael White (http://getsprink.com)
    // -    depends on: include
    // *     example 1: include_once('http://www.phpjs.org/js/phpjs/_supporters/pj_test_supportfile_2.js');
    // *     returns 1: true
 
    var cur_file = {};
    cur_file[window.location.href] = 1;
 
    if (!window.php_js) window.php_js = {};
    if (!window.php_js.includes) window.php_js.includes = cur_file;
    if (!window.php_js.includes[filename]) {
        if(include(filename)){
            return true;
        }
    } else{
        return true;
    }
}

function popen(url) {
	myWindow = window.open(url, 'popen', 'width=1000,height=700,resizable=yes,scrollbars=yes');
	myWindow.focus();
	return false;
}
