﻿$(document).ready(function(){

	/* hide print button on homepage */
   	 if($('div.homepage').size() > 0)
       		 $('.printbutton').hide();    

	$('.pagetools').show();
	$('.fontsize').show();	
	$('#flash_wrapper').show();
	if($('div.banner_teaser_buttons').hasClass('hide')) 
		$('.banner_teaser_buttons').removeClass('hide');
	
	$(".printbutton").click(function() {		
			window.print();			
			return false;
		});
		
	$('.bookmark').click(function() {	
		/*var url = this.href;*/
		var url = window.location.href;		
		/*var title = this.title;*/
		var title = document.title;	
		addBookmark(url,title);
		return false;
	});	
	
	$('.fontsize').sizeswitch();	

	//$('ul.accordion').accordion();	
	
	$('.accordion_wrapper').accordion();	
	
	
	// Banner - Teasers 
	$('.teaser_button').click(function() {
	
		clearInterval(intervalId); // stop auto-switch
		var boxId = this.rel;			
		switchBanner(boxId);		
		return false;
	
	});
	
	
	
	
});	

jQuery.cookie = function (key, value, options) {
    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }
    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};


addBookmark = function (url, title) {
	
	 var ua=navigator.userAgent.toLowerCase();	
	
	 var isMac=(ua.indexOf('mac')!=-1);
     var isWebkit=(ua.indexOf('webkit')!=-1);
	 var isMSIE=(ua.indexOf('msie')!=-1);
	 str=(isMac?'Command/Cmd':'CTRL');
	 
	 if(window.opera && (!opera.version || (opera.version()<9))) {
		str+=' + T';  // Opera versions before 9
    } else if(ua.indexOf('konqueror')!=-1) {
		str+=' + B'; // Konqueror
    } else if(window.opera || window.home || isWebkit || isMSIE || isMac) {
      // IE, Firefox, Netscape, Safari, Google Chrome, Opera 9+, iCab, IE5/Mac
		str+=' + D';
    }
	
	
	 
	// IE 
	if(window.external && isMSIE){    
        try {
			window.external.AddFavorite(url,title);
        } catch(ex){          
          alert('After closing this, press '+str+' to bookmark this page.');
        }
		return false;
	} 
	else if (window.sidebar){ // Firefox
		try {
			window.sidebar.addPanel(title, url,'');
		 } catch(ex){          
          alert('After closing this, press '+str+' to bookmark this page.');
        }
		return false;
	}
	else if (window.opera && window.print){ //Opera	
		addToFav = function(){};
		try {
		!addToFav(url,title);	
		 } catch(ex){ 
			alert('After closing this, press '+str+' to bookmark this page.');
        }
		return false;
		
	 }
	 else {
		alert('After closing this, press '+str+' to bookmark this page.');	
		return false;
	 }
	 
};

switchBanner = function(boxId, bannerBoxes) {

		// hide visible box
		$('.banner_teaser').each(function(index) {
			
			if($(this).is(':visible') && $(this).attr('id') != boxId) {				
				$(this).fadeOut();
			
				if(boxId == 'null') { // auto switch
				
					var toShow = 1;
				
					if(index+1 < bannerBoxes)
						toShow += index+1;	
					
					boxId = $(this).attr('class')+toShow;					
				}
					
			}
			
		});
	
		// show clicked box			
		$('#'+boxId).fadeIn();

}

// auto-switch Banner-Teasers if more than one teaser
$(function() {
	var bannerBoxes = $('.banner_teaser').size();
	if(bannerBoxes > 1)			
		intervalId = setInterval( "switchBanner('null',"+bannerBoxes+")", 7000 );
});




