/*-----------------------------------------
 
 copyright 2009 by mmc
 
 Version: 1.0
 
 Author: Georg Paul, Andreas Nowak
 
 Author URI: http://www.mmc-agentur.at
 
 -------------------------------------------*/


function hideTooltips()
{
  jQuery.each(jQuery('.ext_link_highslide'), function(){
    var cid = $(this).attr('id');
    var expander = hs.getExpander(cid);
    if(expander && $('#external_links').attr('rel') !== 'ext_link_' + cid ) {
        expander.close();
    }   
  });

}

$('#external_links').attr('rel', '');


$(document).ready(function(){
	
	

	$( "#external_links" ).accessNews({
        headline : "Candy Coated",
        speed : "normal",
		slideBy : 2
    });
	
	
	/*  default options for all highslide.js -PopUps (MediaGallery)  */
	hs.graphicsDir = '/fileadmin/system/assets/img/graphics/';
	hs.allowSizeReduction = false;
	hs.showCredits = false;
	hs.dragByHeading = false;
	hs.cacheAjax = false;
	hs.allowSizeReduction = false;
	hs.enableKeyListener = false;
	hs.expandCursor = null;
	hs.preserveContent = false;
	hs.allowMultipleInstances = false;
	

	
	
	/* fallback Link verstecken */
	$(".media_gallery_link").css("display", "none");

	/*  add a link to every Media-Gallery-Init-MarkUp */
	jQuery(".media_gallery_link").each(function() {
		var r = $(this).attr('rel');
		$(this).after( '<a class="highslide hsmg" title="Mediagalerie öffnen" href="/mediagallery.php?id='+ r +'" rel="'+ r +'"><span class="ir">Mediagalerie &ouml;ffnen</span></a>');
	});
	

	jQuery('a.highslide').each(function() {
		this.onclick = function() {
          return hs.htmlExpand(this, {
			contentId: 'ceuid_' + $(this).attr('rel'),
			wrapperClassName: 'borderless hs-blank',
			dimmingOpacity: 0.75,
			align: 'center',
			objectType: 'ajax',
			marginTop: 0,
			width: 980,
			height: 650});
        };
	});
 
 
	hs.Expander.prototype.onAfterExpand = function(sender) {
		var id = this.contentId;
		if(id !== undefined ) {
		
		   if(id.indexOf('ext_link_') == 0) {
			$('#external_links').attr('rel', id);
			hideTooltips();
		   }
						

		   if(id.indexOf('ceuid_') == 0) {
			//var so = new SWFObject('/fileadmin/system/assets/flash/MediaGallery.swf', id, '980', '650', '8', 'none');
			var so = new SWFObject('/fileadmin/system/assets/flash/MediaGallery.swf', id, '100%', '100%', '8', 'none');
			so.addParam('allowScriptAccess', 'sameDomain');
			so.addParam('allowFullScreen', 'true');
			so.addParam('quality', 'high');
			so.addParam('wmode', 'transparent');
			so.addParam('class', 'mediaGallery');
			so.addVariable("xmlURL", rawurlencode('/index.php?type=4&ceuid='+this.contentId.substr(6)));
			so.addVariable("baseURL", "http%3A%2F%2F"+ jsBaseURL +"%2F");
			so.write('media_gallery_flash_' + +this.contentId.substr(6));
			
			// Flash Fallback soll nicht aufblitzen wenn man das Plugin installiert hat
			if ($('#media_gallery_flash_' + +this.contentId.substr(6)).attr("id")) {
				$('#fallback_mg').css("visibility", "visible");
			}
		   }
		
		}		
		
		$("#fallback_mg .close").click(function(event){
			event.preventDefault();
		
			hs.close();
		});		
	}
	 


	
	
   /*
    var documentWidth = $(document).width();
    $("#header").css("position", "static");
    $("#main_nav_wrap").css("width", documentWidth );
    */
     
    //swfobject.registerObject("main_nav_wrapper", "9.0.0", "expressInstall.swf");
	
	


	/* External Links */
	

	$(".ext_link_highslide").hover(function(){
		hideTooltips();
		return hs.htmlExpand(this, {
			targetY: 'external_links -136px',
			width: 165,
			height: 195,
			contentId: 'ext_link_' + $(this).attr('id')
		});
	});
	
	if ( jQuery.browser.msie && jQuery.browser.version == "8.0" ){
		// man bekommt zwar die Linkhand und das href wird angezeigt aber beim Klicken passiert nichts
	 	jQuery('.accessible_news_slider li a').bind('click', function(){
			window.location.href = jQuery(this).attr('href');
		});
	}
	if ( jQuery.browser.msie && jQuery.browser.version == "6.0" ){
		// weil das png dahinter liegt sind die Links nicht klickbar
		jQuery('.ext_links_content').css("position", "static");
		jQuery('.ext_links_content').css("margin-left", "15px");
	}
 
	hs.Expander.prototype.onMouseOut = function(){
		var id = this.contentId;
		if (id.substring(0, 3) == "ext") {
			this.close();
		}
	}

	// csc-uploads icon Breite und Höhe umschreiben	
	jQuery(".csc-uploads-icon img").attr("width", "38");
	jQuery(".csc-uploads-icon img").attr("height", "37");


	// Webradio-Link einfügen und Popup öffnen
	$('#sub_nav li.first').after('<li><a title="Radio" href="javascript:radioPopup();">Radio</a></li>');

	$(".special_section_tv a:first").addClass("teaser_section_link");
	$(".special_section_ra a:first").addClass("teaser_section_link");
	$(".special_section_un a:first").addClass("teaser_section_link");
	
	$("#toggle_tv a").click(function(event){
		event.preventDefault();
		$(".special_section_tv").css("display", "block");
		$(".special_section_ra").css("display", "none");
		$(".special_section_un").css("display", "none");		
	});
	$("#toggle_ra a").click(function(event){
		event.preventDefault();		
		$(".special_section_tv").css("display", "none");
		$(".special_section_ra").css("display", "block");
		$(".special_section_un").css("display", "none");		
	});
	$("#toggle_un a").click(function(event){
		event.preventDefault();		
		$(".special_section_tv").css("display", "none");
		$(".special_section_ra").css("display", "none");
		$(".special_section_un").css("display", "block");	
	});
	
	$("#toggle_un a").trigger('click');
		

});


function closeMediaGallery() {
	hs.close();
}

function bigFlashHandler()
{
	$('#main_nav_wrap').css('z-index', 1001);
	$('#main_nav_wrap').css('height', 550);
	$('#page').css('z-index', 975);
}

function smallFlashHandler()
{
	$('#main_nav_wrap').css('z-index', 975);
	$('#main_nav_wrap').css('height', 50);
	$('#page').css('z-index', 1001);
}

function displayVideo(pageID)
{
	if ($.cookie("video_plays_"+ pageID)) {
		return false;
	}
	else {
		$.cookie("video_plays_"+ pageID, "1");
		return true;
	}

}
function radioPopup(){
	nw=window.open('/radio.html','','width=330,height=320');
	//nw.moveTo((screen.width/2)-330,(screen.height/2)-296.5);
}

function rawurlencode( str ) {
    // URL-encodes string
    //
    // version: 905.1001
    // discuss at: http://phpjs.org/functions/rawurlencode
    // +   original by: Brett Zamir (http://brettz9.blogspot.com)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brettz9.blogspot.com)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Michael Grier
    // +   bugfixed by: Brett Zamir (http://brettz9.blogspot.com)
    // *     example 1: rawurlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin%20van%20Zonneveld%21'
    // *     example 2: rawurlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: rawurlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'

    var histogram = {}, unicodeStr='', hexEscStr='';
    var ret = str.toString();

    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };

    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';


    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);

    for (unicodeStr in histogram) {
        hexEscStr = histogram[unicodeStr];
        ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
    }

    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
}



