(function($){
	$(function(){

		// Fontswitch onload (cookie)
	  if($.cookie('gwh-corporate-fontsize') != null) {
	  	var aCookie = $.cookie('gwh-corporate-fontsize').split('=');			
			if (aCookie instanceof Array) { 
				if(aCookie[0] == 'fontsize' && aCookie[1] == 'large') fontLargeCorporate();
				else if (aCookie[1] == 'small') fontSmallCorporate();
			}
		}
		else fontSmallCorporate(); // kein Cookie gesetzt
		
		// Fontswitch onclick
		$('a.large').click(function(){ // large
    	fontLargeCorporate();
		});
		$('a.small').click(function(){ // small
			fontSmallCorporate();
		});
		
		// Fontswitch large
		function fontLargeCorporate() {
			$('a.small').removeClass('act');
			$('a.large').addClass('act');
    	$('#linkeSpalte').css('fontSize','85%');
			$('#startseiteLinkeSpalte').css('fontSize','85%');
			$('#rechteSpalte').css('fontSize','85%');
			$('#startseiteRechteSpalte').css('fontSize','85%');
			$.cookie('gwh-corporate-fontsize', 'fontsize=large', { expires: 0, domain: 'www.gwh.de', path: '/' });
		}

		// Fontswitch small
		function fontSmallCorporate() {
			$('a.large').removeClass('act');
			$('a.small').addClass('act');							
			$('#linkeSpalte').css('fontSize','75%');
			$('#startseiteLinkeSpalte').css('fontSize','75%');
			$('#rechteSpalte').css('fontSize','75%');
			$('#startseiteRechteSpalte').css('fontSize','75%');
			$.cookie('gwh-corporate-fontsize', 'fontsize=small', { expires: 0, domain: 'www.gwh.de', path: '/' });
		}
		
		// Kontrastswitcher onload (cookie)
	  if($.cookie('gwh-corporate-kontrast') != null) {
	  	var aCookie = $.cookie('gwh-corporate-kontrast').split('=');			
			if (aCookie instanceof Array) { 
				if(aCookie[0] == 'kontrast' && aCookie[1] == '1') kontrastOnCorporate();
				else if (aCookie[1] == '0') kontrastOffCorporate();
			}
		}
			
		// Kontrastswitcher onclick		
		$('#kontrast a img').live('click',function(){
    	if($(this).attr('src') == 'fileadmin/templates/img/kontrast.jpg') kontrastOnCorporate(); // Kontrast an
			else kontrastOffCorporate(); // Kontrast aus
		});

		// Kontrast An
		function kontrastOnCorporate() {
			$('#kontrast a img').attr('src','fileadmin/templates/img/kontrast_active.jpg');
			$('#kontrastStylesheet').attr('href','fileadmin/templates/css/kontrast.css');
			// Cookie setzen - Verfallsdatum 90 Tage
			$.cookie('gwh-corporate-kontrast', 'kontrast=1', { expires: 0, domain: 'www.gwh.de', path: '/' });
			$('#logo').css('backgroundImage',"url('/fileadmin/templates/img/gwh_logo_schwarz.png')");
			$('#logoFusszeile img').attr('src','fileadmin/templates/img/gwh_logo_footer_schwarz.gif');				
		}
		
		// Kontrast Aus 
		function kontrastOffCorporate() {
			$('#kontrast a img').attr('src','fileadmin/templates/img/kontrast.jpg');
			$('#kontrastStylesheet').attr('href','fileadmin/templates/css/kontrast_empty.css');
			// Cookie setzen
			$.cookie('gwh-corporate-kontrast', 'kontrast=0', { expires: 0, domain: 'www.gwh.de', path: '/' });
			$('#logo').css('backgroundImage',"url('/fileadmin/templates/img/gwh_logo.png')");
			$('#logoFusszeile img').attr('src','fileadmin/templates/img/gwh_logo_footer.gif');		
		}
		
		// Startseite Modul E - random content (ID c1151)
		if ($('#c1151').length > 0 ) {
			var iC = 0;
			var iSize = Math.floor(Math.random() * $('#c1151 .csc-default').length);
			$('#c1151 .csc-default').each(function() {;
				if (iC == iSize) {
					$(this).css('display','block');
					return false; // break each
				}
				iC++;
			});
		}

/*
		// Tweet Button
		// Popup Position relativ zur Größe des Browserfensters setzen - Anfang
		$.event.add(window, 'load', setPopupPos);
		$.event.add(window, 'resize', setPopupPos);
		var popUpX = 250;
		var popUpY = 350;
		function setPopupPos() {
			popUpX = $(window).width()/2-200;
			popUpY = $(window).height()/2-165;
		}
		// Popup Position relativ zur Größe des Browserfensters setzen - Ende
		$('span.twitter').click(function(){
			
			 var twitter = window.open('https://twitter.com/share?url='+encodeURI(document.URI), "tweet",
			 	"screenX="+popUpX+",screenY="+popUpY+",menubar=no,toolbar=no,dependent=yes,width=400,height=330,resizable=no,status=no,scrollbars=no,location=no");
 			 twitter.focus();
		});

		//alert('http://www.facebook.com/sharer/sharer.php?u='+document.URL); // Facebook unterbindet die Anzeuge der sharer.php im iframe
		// Facebook Share Button
		$('span.facebook').click(function(e){
			e.preventDefault();
			FB.ui({
				method: 'feed',
				//display: 'popup',
				link: document.URL, // Link-URL
				name: $('title').html(), // Linkname
				picture: encodeURI('http://www.gwh.de/fileadmin/templates/img/gwh_logo.png'),
				description: $("meta[name=description]").attr('content'), // Linkbeschreibung
				message: 'Ihr Kommentar...' // Prefill textfield
			});
			
			jQuery.fn.ceebox.popup(
				'<a href="'+url+'?app_id='+appId+'&link='+link+'&picture='+picture+'&name='+name+'&caption='+caption+
				'&description='+description+'&message='+message+'&redirect_uri='+redirect_uri+'">Facebook share</a>', {
				type:'html',
				htmlWidth:640,
				htmlHeight:480,
				titles:false,
				padding:0
			});
		});
*/
		
		// Expose-Mieten Auswahl "alle Bilder (n) ansehen" generieren
		if ($('.expose span.bilder').length > 0) {
			$('.expose span.bilder a').each(function(){
				var oLink;
				if ($(this).attr('class') == 'img_1') {
					oLink = $(this).clone().html('alle Bilder (<span class="expose_anz_bilder">'+$('.expose span.bilder').children().length+'</span>) ansehen')
				}
				else {
					oLink = $(this).clone().html('');
				}
				oLink.attr('rel','lightbox[expose2]');
				$('.expose .caption').append(oLink);
			});
		}
	
	});
})(jQuery);
