/**
 * central jQuery init block
 * @project WHITE-LABEL
 * @notes alle CSS-Abhaengigkeiten sind ggf. projektspezifisch anzupassen!
 * @see http://docs.jquery.com/Selectors
 */




// Language definition for QuickSearch
var quickSearchText = {
    "de" : "Suche",
    "en" : "Search"
};

var tabNavigationFix = function () {
  /*
  Here could be checked the positioning of the layer for the second level
  navigation. I. e. wether the layer would overlap the right page limit in
  default position, this may be fixed here ... 
  */


  /* Fixes the missing LI:hover for IE6 ... */
  if (false && // nobody wants this ;-)
  $.browser.msie &&
  $.browser.version.indexOf("6") === 0) {
    $(".TabNavigation>UL>LI").mouseover(function() {
      $(this).children("DIV.second-level").css("display", "block")
    });
    $(".TabNavigation>UL>LI").mouseout(function() {
      $(this).children("DIV.second-level").css("display", "none")
    });
  }
}


$(document).ready(
  function() {


    ///////////////////////////////////////////////////
    // ContentImages in Content with caption / legend needs a width fix
    // found @http://www.blogrammierer.de/jquery-bildbreite-ermitteln-um-bildunterschriften-korrekt-darzustellen/ 
    $(".ContentImage").each(
        function(){
            var width = $(this).children(".ContentImageWrapper").children("IMG").width() || $(this).children(".ContentImageWrapper").children("A").children("IMG").width();
            $(this).css("width", width);
        }
    ); 






		if (typeof(jsPathPrefix) === "undefined") {
			jsPathPrefix = "";
		}
    ///////////////////////////////////////////////////
    //supersleight
    if($.browser.msie && parseFloat($.browser.version) < 7) {
      $('div#PageWrapper').supersleight();
    }


    ///////////////////////////////////////////////////
    //Menuelayer geht nach links auf wenn der Menuepunkt zu weit rechts steht, damit der Layer nicht nach rechts rausragt
    var offsetDiv = $('div.TabNavigation').offset();
    $('div.TabNavigation>ul>li').each(function(){
      var offsetLi = $(this).offset();
      //alert(offsetLi.left - offsetDiv.left);
      if ((offsetLi.left - offsetDiv.left) > 600) {
        $(this).find('div.second-level').attr({style: "left: auto; right: -14px; background-position: right top !important;"});
      }
      if ((offsetLi.left - offsetDiv.left) > 450) {
        $(this).find('div.second-level.large').attr({style: "left: auto; right: -14px; background-position: right top !important;"});
      }
    });

    $('div.second-level.large div.Rubrik:even ul.LinkList').attr({style: "margin-right: 30px !important;"});
    $('div.second-level.large div.Rubrik:first-child').attr({style: "margin-bottom: 20px;"});
    $('div.second-level.large div.Rubrik:nth-child(2)').attr({style: "margin-bottom: 20px;"}).after('<br class="clear" />');

    //Tabellen einfaerben
    $('div#ContentContainer div.ContentCol table tr:nth-child(2n)').addClass("even");
    //$('div#ContentContainer div.ContentCol table tr:first-child').addClass("head");
    //kein Trenner nach im ersten Sitetool
    $('ul.Sitetools li:first-child').attr({style: "background-image: none;"});
    //List margins in Boxes
    $('div.Box ul:first-child').css('margin-top','0px');
    $('div.Box ul:only-child').css('margin-top','0px');
    $('div.Box ul:last-child li:last-child').attr({style: "padding-bottom:0px; border-bottom: 0px; margin-bottom: 0px"});
    $('div.Box ul:last-child').css('margin-bottom','0px');
    $('div.Box p:last-child').attr({style: "margin-bottom: 0px"});
    $('div.Box span p:last-child').attr({style: "margin-bottom: 0px"});
    $('div.BoxContent div.InhaltFotoKlein:odd').after('<div class="clear"></div>');
    //Wenn Navigationspunkt Unterpunkte enthaelt, dann Pfeil nach unten
    $('div.Navigation li ul').parent().addClass("open"); 
    $('div.Navigation li.active ul li.active').parent().parent().removeClass("active");
    $('div.BranchNavigation ul li:last-child a').attr({style: "border:none"});
    $('ul.LinkList li ul').parent().addClass("open"); 
    //Downloads(ua Links) via CSS-Klasse mit Typ-Icon versehen: hier ist der Link innerhalb eines li und die class muss dort ran! 
    $('div.BoxLink > a[href$=.pdf]').parent().addClass("PDF");
    $('div.BoxLink > a[href$=.doc]').parent().addClass("DOC");
    $('div.DetailLink > a[href$=.pdf]').parent().addClass("PDF");
    $('div.DetailLink > a[href$=.doc]').parent().addClass("DOC");
    $('a[href$=.pdf]').addClass("PDF");
    $('a[href$=.doc]').addClass("DOC");
    $('a[href$=.rtf]').addClass("DOC");
    $('a[href$=.xls]').addClass("XLS");
    $('a[href$=.zip]').addClass("ZIP");
    $('a[href$=.mov]').addClass("MOV");
    $('a[href$=.mp3]').addClass("MP3");
    $('a[href$=.txt]').addClass("TXT");
    $('ul.LinkList li > a[href$=.pdf]').parent().addClass("PDF");
    $('ul.LinkList li > a[href$=.doc]').parent().addClass("DOC");
    $('ul.LinkList li > a[href$=.rtf]').parent().addClass("DOC");
    $('ul.LinkList li > a[href$=.xls]').parent().addClass("XLS");
    $('ul.LinkList li > a[href$=.zip]').parent().addClass("ZIP");
    $('ul.LinkList li > a[href$=.mov]').parent().addClass("MOV");
    $('ul.LinkList li > a[href$=.mp3]').parent().addClass("MP3");
    $('ul.LinkList li > a[href$=.txt]').parent().addClass("TXT");
    $('ul.LinkList li > a[href$=.png]').parent().addClass("IMG");
    $('ul.LinkList li > a[href$=.jpg]').parent().addClass("IMG");
    $('ul.LinkList li > a[href$=.gif]').parent().addClass("IMG");
    $('ul.LinkList li > a[href$=.bmp]').parent().addClass("IMG");
    $('h6 a[href$=.pdf]').parent().addClass("LinklisteInhaltPDF");
    $('div.BoxLinkPDF > a.PDF, div.BoxLinkpdf > a.PDF, div.BoxLink.PDF > a.PDF, div.BoxDownload .BoxLink > a.PDF').removeClass("PDF");
    $('div.BoxLinkWord > a.DOC, div.BoxLink.DOC > a.DOC').removeClass("DOC");
	$('.BoxVideo .BoxLink > a.MP3').removeClass("MP3");

    ///////////////////////////////////////////////////
    //alle absoluten URIs im extra Fenster öffnen
    $("a[href^='http'],area[href^='http']").click(function() {
      this.target = "_blank";
    });


    ///////////////////////////////////////////////////
    // Scroll
    $('a.scroll, #Totop').bind("click", function(event){
      $(this).scrollTo(event);
    });
    //$('#Totop').animate( { scrollTop: 0 }, 'slow' );



    ///////////////////////////////////////////////////
    // Tabs
    $('.Tabs.OnePage').tabs({ selected:0, fx: {opacity: 'toggle', duration: 'normal'} });
    $('.Tabs.Aktie').tabs({ selected:0, fx: {opacity: 'toggle', duration: 'normal'} });
    $('div.ContentCol div.Tabs:first-child').attr({style: "margin-top: 35px;"});
    $('div.Tabs ul.ui-tabs-nav li:first-child').addClass("first");

    ///////////////////////////////////////////////////
    // Langage Selector umstylen
    $('div.LanguageSelector a').hide();
    $('div.LanguageSelector select').show();
    var sObj =  $('div.LanguageSelector');
    if(jQuery.isFunction($.fn.select2div)) {
      $('div.LanguageSelector').each(function(){
        var self = $(this);
      
        self.select2div(function(data) {
            if(jsPrefix){
              jumpVS(data, jsPrefix);
            } else {
              jump(data);

            }
          }
        );
      });
    }
  

  
    ///////////////////////////////////////////////////
    // Brancehselektor umstylen
    if($('div.branch_select').length) {
      if(jQuery.isFunction($.fn.select2div)) {
        $('div.branch_select').each(function(){
          var self = $(this);


          var topText = self.find('select option:first-child').html()
          var activeCounter = self.find('select option:selected').index();
          var activeData = self.find('select option:selected').attr("value");

          self.select2div(function(data) {
              if(data != activeData) {
                location.href = data;
              } else {
                self.find("div.select2div_select span").html(topText); 
              }
            },
            function() {
              self.find("div.select2div_select span").hide();
              self.find("div.select2div_dropdown ul li:eq("+activeCounter+")").addClass("active");
              self.find("div.select2div_dropdown ul li:last-child a").attr({style: "border:none"});
            },
            function(data){
              $("div.branch_select div.select2div_select span").show();
            }
          );


          self.find("div.select2div_select span").html(topText);    
      });
      }
    }

    ///////////////////////////////////////////////////
    // Akkorden Animation
    $(".accordion").accordion({ 
            animated: 'slide', 
            collapsible: true,
            autoHeight: false,
            active: false
    });
    $(".TeaserAcc").accordion({ 
            animated: 'slide',
            collapsible: true,
            autoHeight: false,
            active: false
    });
    $(".ReadmoreAcc").accordion({ 
            animated: 'slide',
            collapsible: true,
            autoHeight: false,
            active: false
    });
    ///////////////////////////////////////////////////
    // Quicksearch
    //$('input#QuickSearch').attr('value', 'Test');
	try {
	    var qsOptions = {
	      elemForm: $("#QuicksearchForm"),
	      elemInput: $('input#QuickSearch'),
	      elemSubmit: $('#QuickSearchForm input[type=submit]'),
	      elemInputDefaultVal: $('input#QuickSearch').attr('value'),
	      elemFancy: $('div.qsLayerFancy'),
	      elemLayer: $('div.qsLayer'),
	      elemContent: $('#qsLayer_suggest'),
	      searchLang: currentPageLanguage,
	      searchUrl: QuickSearchSearchUrl,
	      suggestUrl: QuickSearchSuggestUrl,
	      tagCloudUrl: QuickSearchTagCloudUrl,
	      elemTagCloud: $('#qsLayer_tagcloud')      
	    };
	    $("div.QuickSearch").quicksearch(qsOptions);
	} catch(e) {}



    ///////////////////////////////////////////////////
    // MovingBoxes
    if($(".scrollContainer").length) {
      var mb = new SH.helper.MovingBoxes()

      // CSS für inaktive Elemente
      mb.inactiveItemCss = {
        width: 133,
        height: 150,
        'subcss': {
          'img': { 
            width:136, 
            height:93
          },
          'p': {
            'font-size':10
          }
        }
      }

      // Moving Boxes CSS für Items definieren
      mb.activeItemCss = {
        width: 160,
        height:150,
        'subcss': {
          'img': { 
              width:160, 
              height:110 
            },
          'p': {
            'font-size':12
          }
        }
      }

      mb.animationSpeed = 500 // Wie schnell soll alles laufen?
      mb.init()// Moving Boxes initialisieren
    }


    ///////////////////////////////////////////////////
    // Misc.
    /*
    $("div.branch_select").click(function() {
      $(this).parent().find('div.branch_dropdown').show();
    });

    $("div.branch_dropdown").click(function() {
      $('div.branch_dropdown').hide();
    });
*/
    $("INPUT.NumberField").keyup(function() {
      $(this).val(this.value.replace(/\D/, ""));
    });


});


/*
//Country Ziellinks
function jump(x)
    {
    if(x==1) window.open ('/INTERNET/major/pool/index.html?sLang=en','_self','');
    if(x=='1.2') window.open ('/INTERNET/major/pool/index.html?sLang=de','_self','');
    if(x=='x1') window.open ('index.html?sLang=en','_self','');
    if(x=='x1.2') window.open ('index.html?sLang=de','_self','');
    if(x==2) window.open ('/INTERNET/minor/br/index.html','_self','');
    if(x==3) window.open ('/INTERNET/major/cn/index.html','_self','');
    if(x==4) window.open ('/INTERNET/minor/fr/index.html','_self','');
    if(x==5) window.open ('/INTERNET/major/pool/index.html?sLang=de','_self','');
    if(x=='x5') window.open ('index.html?sLang=de','_self','');
    if(x==6) window.open ('/INTERNET/minor/uk/index.html','_self','');
    if(x==7) window.open ('/INTERNET/minor/in/index.html','_self','');
    if(x==8) window.open ('/INTERNET/minor/it/index.html','_self','');
    if(x==9) window.open ('/INTERNET/minor/mx/index.html','_self','');
   if(x==10) window.open ('/INTERNET/minor/ru/index.html','_self','');
   if(x==11) window.open ('/INTERNET/minor/sk/index.html','_self','');
   if(x==12) window.open ('/INTERNET/minor/es/index.html','_self','');
   if(x==13) window.open ('/INTERNET/major/us/index.html','_self','');
    }


//	1 - Schuler Homepage
//	2 - Brasil
//	3 - China
//	4 - France
//	5 - Germany
//	6 - Great Britain
//	7 - India
//	8 - Italy
//	9 - Mexico
//	10 - Russia
//	11 - Slovakia
//	12 - Spain
//	13 - USA


function jumpVS(x,pre)
{
    if(x==1) window.open (pre + '/INTERNET/major/pool/index.html?sLang=en','_self','');
    if(x=='1.2') window.open (pre + '/INTERNET/major/pool/index.html?sLang=de','_self','');
    if(x=='x1') window.open ('index.html?sLang=en','_self','');
    if(x=='x1.2') window.open ('index.html?sLang=de','_self','');
    if(x==2) window.open (pre + '/INTERNET/minor/br/index.html','_self','');
    if(x==3) window.open (pre + '/INTERNET/major/cn/index.html','_self','');
    if(x==4) window.open (pre + '/INTERNET/minor/fr/index.html','_self','');
    if(x==5) window.open (pre + '/INTERNET/major/pool/index.html?sLang=de','_self','');
    if(x=='x5') window.open ('index.html?sLang=de','_self','');
    if(x==6) window.open (pre + '/INTERNET/minor/uk/index.html','_self','');
    if(x==7) window.open (pre + '/INTERNET/minor/in/index.html','_self','');
    if(x==8) window.open (pre + '/INTERNET/minor/it/index.html','_self','');
    if(x==9) window.open (pre + '/INTERNET/minor/mx/index.html','_self','');
   if(x==10) window.open (pre + '/INTERNET/minor/ru/index.html','_self','');
   if(x==11) window.open (pre + '/INTERNET/minor/sk/index.html','_self','');
   if(x==12) window.open (pre + '/INTERNET/minor/es/index.html','_self','');
   if(x==13) window.open (pre + '/INTERNET/major/us/index.html','_self','');
}

*/

