$(document).ready(function(){
  accordion.init();
  quicknav.init();
  subnav.init();
  
  $("#bookmark").show();
  $("#print").show();
  
  $("#normal").hide();
  $("#normal").fadeIn();			
  
  $("#normal .csc-textpic A IMG").resize();
    
   $("#mailformTelefon").bind("focus",function(e){
     if(document.getElementById("err") != null) $("#err").remove();
   });
  
   $("#mailformTelefon").bind("blur",function(e){
      $(this).validate('phone');
    });
  
  
});



(function($) {
    $.fn.resize = function() {
    var _h=0;var _w=0;var _src='';
  
    $(this).parent().bind("click",function(e){
    
      var src=this.href;
      var elem = $("IMG",this)
         
          if(_h==0 && _w==0) {
            _h=elem.attr('height');
            _w=elem.attr('width');
            _src=elem.attr('src');
          }
          elem.attr('src',this.href);
          var h=(elem.attr('height')==457)?_h:457;
          var w=(elem.attr('width')==600)?_w:600;
          
          
          elem.animate( { width:w+"px",height:h+"px"}, { queue:true, duration:1000, complete:function(){
            if($(this).attr('width')==_w) this.src=_src;
          } } );
      return false;
      });
      
    }
})(jQuery);



/** validate email
 * @param String type
 */ 
$.fn.validate = function(type){  

  var regEx;
  var valid=false;
  var form =$(this).parent();


  switch (type) {
    case 'email':
        regEx=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
        valid = regEx.test(this.val());
                
        
        while(form.attr('nodeName')!='FORM' ) form=form.parent();
        
        /* reset style & function */
        $(form).unbind('submit');
        this.attr('style', '');
        
        /* not valid */
        if (!valid){ 
          $(form).submit(function() {return false;});
          this.attr('style', 'color:red');
        }
        
        
    break;
    
    case 'phone':
        if(document.getElementById("err") != null) $("#err").remove();
        this.removeClass("input-err");
        regEx=/^([0-9\-\+()\/ ]*)$/;
        valid = regEx.test(this.val());
        
        if ( valid ) {
          valid =(this.val().length > 6);
          err="Ihre Telefonnummer ist zu kurz.<br><b>Vorwahl & Telefonnummer</b>";
        } else {
          err="Bitte überprüfen Sie Ihre Telefonnummer.<br/>Es wurde ein <b>falsches Format</b> oder <b>Buchstaben</b> eingegeben.";
        }
        
        while(form.attr('nodeName')!='FORM' ) form=form.parent();
        
        /* reset style & function */
        $(form).unbind('submit');
        this.attr('style', '');
        
        /* not valid */
        if (!valid){ 
          $(form).submit(function() {return false;});
          // this.attr('style', 'color:red');   
          this.addClass("input-err");       
          this.parent().append( "<p id=\"err\">"+err+"</p>");
            
        }
    break;
  }
}




var accordion = {
  init:function() {  	
	$("#left H1").next(".accordionItem").hide();
	var elem = $('.accordionItem', '#left').get(1);
	    $(elem).prev().toggleClass("accordion-act");	
	$("#left .accordion-act").next().show();
 	$("#left H1 A").click(function(){
   	 	if($(this).parent().is('.accordion-act')) {
   	 	
   	 	} else {
   	 	  $(".accordion-act").next(".accordionItem").slideUp('fast');
   	 	  $(".accordion-act").removeClass("accordion-act");
   	 	
   		  $(this).parent().toggleClass("accordion-act");
   	    $(this).parent().next(".accordionItem").slideDown();
   	  }
   	
 		});
     
  }
  
}

var subnav = {
  init:function() { 
  $("#navMain UL LI.act").hide();; 
  $("#navMain UL LI.act").fadeIn("fast");;
  }	
  
}

var quicknav = {
  init:function() {
	$("#left .csc-menu LI").hide();
	
  var elem = $('.csc-menu LI', '#left').get(0);
	    $(elem).toggleClass("first");

	$("#left .csc-menu LI.first").show();
 
  $("#left .csc-menu").bind("mouseenter",function(){
      $("LI",this).fadeIn();
    }).bind("mouseleave",function(){
      $("LI",this).hide();
      $("LI.first",this).show();
      
    });
  }
  
}





function bookmark(){
  var bmUrl=location.href;
  var bmTitle=(document.getElementsByTagName("title")[0].text);
 
  if (window.sidebar){
    // firefox
    window.sidebar.addPanel(bmTitle,bmUrl,"");
  } else if(window.opera && window.print) {
    // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',bmUrl);
    elem.setAttribute('title',bmTitle);
    elem.setAttribute('rel','sidebar');
    elem.click();
    } else if(document.all)  {
    // ie
    window.external.AddFavorite(bmUrl,bmTitle);
    }
    return false;
}





 

