
//After import of this js it will instantiate the document and jqueryobject:
if (!window.Openair) Openair = {}
Openair.jq = jQuery;
var hans;

//after load page do:
Openair.jq(document).ready(function() {    
    
    //add some Mousevent to eachnavigatonelement and set the active navigation
          $("#navigation a img").each(function(i){            
            $(this).mouseover(function(){
                this.src = checkActiveNavigation(this.src,true);                 
            }); 
            $(this).mouseout(function(){            
                this.src = checkActiveNavigation(this.src,false); 
            });             
            $(this).attr('src',checkActiveNavigation($(this).attr('src'),false));                            
          });
      
        setWrapperSize();              
        showSponsorPics = true;          
        getSponsorBar();

      
});


function getSponsorBar(){

sponsorbar = Openair.jq('#sponsoren');

      var arrOfSponsorImg =  new Array(
            new Array('images/sponsoren/Appenzeller-Bier-logo.jpg',
                      'Appenzellerbier, natürlich und mit dem Mond gebraut!',
                      'http://www.appenzellerbier.ch'
                      ),
             new Array('images/sponsoren/logo_thegoldencatapult.com.png',
                      'Vertreibe Deine Songs online und ohne Kosten!',
                      'http://www.thegoldencatapult.com'
                      ),
             new Array('images/sponsoren/ixsologo.jpg',
                      'Gerne etwas Energie ohne Chemie? 100% natürlich! Eine herrliche Kombination: erfrischend, nicht überzuckert wie andere Energy Drinks, speziell, fruchtig, sprudelig!',
                      'http://ixso.ch'
                      ),
             new Array('images/sponsoren/LogoAWS.jpg',
                      'Soundengineering das überzeugt!',
                      'http://www.ams-soundtechnik.ch/AMS-Soundtechnik/Home.html'
                      ),
             new Array('images/sponsoren/LogoSchmidli.jpg',
                      'Elektro Schmidli, einfach etwas besser anders!',
                      'http://www.elektroschmidli.ch'
                      ),
             new Array('images/sponsoren/MeikoService.png',
                      'Meiko und alles ist in bester Ordnung!',
                      'mailto:nprossek@bluewin.ch'
                      ),
             new Array('images/sponsoren/zaunteam.png',
                      'Zaunteam - Finden Sie den Zaun, der Ihren individuellen Bedürfnissen gerecht wird!',
                      'http://www.zaunteam.com/nordwest'
                      ),
             new Array('images/sponsoren/SchluesselLogo.jpg',
                      'Gasthof zum Schlüssel, entschieden richtiger!',
                      'http://www.gasthof-schluessel.ch'
                      ),
             new Array('images/sponsoren/uljLogo.jpg',
                      'Webseiten die Sie einfach selbst aktualisieren können!',
                      'http://www.universallink.ch'
                      ),
             new Array('images/sponsoren/wegweiser_gt_150w.png',
                      'Das Team vom Grüana Tuuma wünsch schöne Ferien im eigenen Garten!',
                      'http://www.schmuzli.ch'
                      ),
             new Array('images/sponsoren/zellermarkt.png',
                      'Das Team des Zeller Markt, der Agro Zeller GmbH und des Zaunteam Nordwest freut sich auf Ihren Besuch',
                      'http://www.zellermarkt.ch/'
                      ),
             new Array('images/sponsoren/rfv.ch.jpg',
                      'Der RFV engagiert sich besonders für die qualitative Verbesserung der Rahmenbedingungen für junge Musiker in der Region.!',
                      'http://www.rfv.ch'
                      ),
             new Array('images/sponsoren/pap-weber.ch.gif',
                      'Vorverkaufstelle und Papeterie Weber Oberdorf',
                      'http://www.pap-weber.ch'
                      ),
             new Array('images/sponsoren/sponsoring.png',
                      '4. Sind Ihre Kunden es nicht Wert speziel gepflegt zu werden, z.B. am Openair Waldenburg?',
                      'sponsoren-unterstuetzen-das-openair.php'
                      ),
             new Array('images/sponsoren/logo_brandsystem.ch.png',
                      'Markenagentur BrandSystem – Agentur für Branding, Marketing und Design',
                      'http://www.brandsystem.ch'
                      ),
             new Array('images/sponsoren/denova-wohnen.jpg',
                      'Denova hilft Ihnen gerne, Ihr zu Hause zu Ihrer eigenen Wohlfühloase umzugestalten. ',
                      'http://www.denova-wohnen.ch'
                      )
                    );  
     //Shuffle the Array !
      var tmp, rand;
      for(var i =0; i < arrOfSponsorImg.length; i++){
        rand = Math.floor(Math.random() * arrOfSponsorImg.length);
        tmp = arrOfSponsorImg[i]; 
        arrOfSponsorImg[i] = arrOfSponsorImg[rand]; 
        arrOfSponsorImg[rand] =tmp;
      }
            
      for (var id in arrOfSponsorImg) {
      //alert('Sali');
				var myli = document.createElement('li');
				var mya = document.createElement('a');
				var myimg = document.createElement('img');				
				mya.appendChild(myimg);	
        myli.appendChild(mya);			
        
        $(myimg).attr('src',arrOfSponsorImg[id][0]);	
				
			$(mya).attr('href',arrOfSponsorImg[id][2])
			      .attr('title',arrOfSponsorImg[id][1]+' visit:'+arrOfSponsorImg[id][2])
            .attr('target','_blank');				
				sponsorbar.append(myli);
			}
			window.setTimeout('startSponsorBarAnimation()',5000);
      
}

function arrayShuffle(){
  var tmp, rand;
  for(var i =0; i < this.length; i++){
    rand = Math.floor(Math.random() * this.length);
    tmp = this[i]; 
    this[i] = this[rand]; 
    this[rand] =tmp;
  }
}



function startSponsorBarAnimation(){
      hasHideOne = false;
      hasShowOne = false;
      countHiddenElements = 0;
      countAllElements2 =0;
      countAllElements = Openair.jq('#sponsoren li').siblings().length;     
      Openair.jq('#sponsoren').children().each(function(i){
           if($(this).css('display')== 'none'){          
            countHiddenElements++;            
           }      
           countAllElements2++;
      });   
      if(countHiddenElements == 0) showSponsorPics=true;
      
//alert(showSponsorPics+'  countAllElements2='+countAllElements2+'  '+countHiddenElements +' == '+countAllElements);    
//window.status= showSponsorPics+'  countAllElements2='+countAllElements2+'  '+countHiddenElements +' == '+countAllElements;
//alert(countAllElements+' '+countHiddenElements+' '+hasHideOne+' '+hasShowOne);
      Openair.jq('#sponsoren').children().each(function(i){    
            if(showSponsorPics && !hasHideOne){                     
                 if($(this).css('display')== 'block'){
                  $(this).fadeOut(2500);     
                  hasHideOne = true;              
                 }  
            }else{
                  if($(this).css('display')== 'none' && !hasShowOne){
                    $(this).show(1500);     
                    hasShowOne = true;              
                 }  
            
            }  
            if(countHiddenElements == countAllElements) showSponsorPics=false;           
      });    
    nextActAfter = (Math.round(Math.random()*10000/2));    
    window.setTimeout('startSponsorBarAnimation()',nextActAfter);
}





/*
*   Defining the used functions
*
*/


//changes the navigation image on mousevent
function checkActiveNavigation( myImgPath, isMouseOver){
 
  myImgSrc = myImgPath.substring(myImgPath.lastIndexOf('/')+1,myImgPath.indexOf('.png')+4 ); // ergibt 'index_active.png'
  myPath= myImgPath.substring(0,myImgPath.lastIndexOf('/'));
  actualSite = myImgSrc.substring(0,myImgSrc.indexOf('.png') ); //ergibt 'index_active'

  //actualSite = myImgSrc.substring(myImgSrc.lastIndexOf('/')+1,myImgSrc.indexOf('.png') );
  
  if(actualSite.search('_')>0){
    actualSite = actualSite.substring(0,actualSite.indexOf('_') );    //ergibt 'index' 
  }
  
  //if it is the active site
  if(document.URL.search(actualSite)>0 ){
    //if it is the active site
      return myPath + '/' + actualSite + '_active.png';
  }else{
    if(isMouseOver){
      return myPath + '/' + actualSite + '_over.png';
    }else{
      return myPath + '/' + actualSite + '.png';
    }
  }
}


function setWrapperSize(){
 
  //korrektur für Top
  var korrektur = 210;
  
  var sichtbereich=0;
  
  //IE && other compatibility
  if(window.innerHeight == undefined){  
      sichtbereich = document.documentElement.clientHeight;        
  }else{
      sichtbereich = window.innerHeight;
  }
  
  var body = document.getElementById("page");
  var myWrapper = document.getElementById('wrapper');
  var myInhalt = document.getElementById('inhalt');
  var mySponsorBar = document.getElementById('sponsoren');

// falls kleiner sichtbarer bereich als Minimale Höhe
// schalte den div-scrollbar aus und den hauptscrolbar ein
     if(sichtbereich < 750){      
      //body.style.overflow = body.style.overflow == "hidden" ? "auto" : "hidden";
      body.style.overflow = "auto";    
      myWrapper.style.overflow = "auto";
      myInhalt.style.overflow = "hidden";
    }else{
      myWrapper.style.height= (sichtbereich-10)+'px';
      myInhalt.style.height= (sichtbereich-korrektur)+'px';
      mySponsorBar.style.height= (sichtbereich-korrektur+15)+'px';
      myWrapper.style.overflow = "hidden";   
      
      
    }
 
   /*var Auswertung
  Auswertung = (Bedingung) ? AlternativeTrue : AlternativeFalse*/
}






function Calculate (noAlert, preisWEPass) {
  
  meng = document.getElementById('menge').value;
  ind = document.getElementById('prod').selectedIndex
  je = 0;
  if(ind == 0 || meng ==0){
     if(!noAlert) {
       alert("Bitte wählen Sie die Anzahl und die gewünschte Art der Tickets");
       return false;
     }
  }else if(ind == 1){
    je = preisWEPass;
  }else if(ind == 2){
    je = 19;
  }else if(ind == 3){
    je = 29;
  }  
    document.getElementById('summe').innerHTML = "<b><font style='color: green;'>&nbsp;= CHF "+ meng * je +" </font></b>";
    document.getElementById('zuJe').value = je ;
    document.getElementById('totale').value = meng * je +"";
    return true;
}

function CalculateAdmin(){
  anz = document.getElementById('anz').value;
  je  = document.getElementById('je').value;
  document.getElementById('total').value = anz*je;
  //alert(anz+' * '+je +' = '+ je*anz );
}



/*
Array.prototype.shuffle =arrayShuffle;

zahlen.shuffle();

var ausgabe = zahlen.join(", ");
alert(ausgabe);

*/


