var profiles = 
{
	mediathek:
	{
		height:600,
		width:960,
		scrollbars:1
	}
};
$(function(){		
	$(".tx-imagecycle-pi1 a").popupwindow(profiles);
	$("a.mediathek").popupwindow(profiles);
	
	/** WAI-ARIA für das Kontaktformular **/
    $('form .required').attr('aria-required', 'true');
    $('form div.error input.required').attr('aria-invalide', 'true');
    $('form div.error').attr('aria-live', 'assertive').attr('role', 'alert');
    
    /** Formularvalidierung **/
    $('form').submit(function(){
        var error = false;
        $('.required', $(this)).each(function() {
            var $this = $(this);
            var email = false;
            $this.parent('div').removeClass('error').removeAttr('role').removeAttr('aria-live');
            $this.removeAttr('aria-invalide');
            $this.siblings('label[class*="error"]').remove();
            if($this.attr('class').split(' ').slice(-1) == "email") {
                if(/^[\w-+\.]+@([\w-]+\.)+[\w-]{2,}$/i.test($this.val())) {
                    email = false;
                }
                else {
                    email = true;
                }
            } 
            if($this.val().length == 0 || email ) {
                error = true;
                $this.parent('div').addClass('error').attr('role', 'alert').attr('aria-live', 'assertive');
                if($this.siblings('label[class*="error"]').length == 0) {
                    var $label = $this.siblings('label');
					var name = $label.attr('for'); 
                    var text = $label.text().split('*');
                    if(email) {
                        $label.before('<label class="error" for="' + name + '">Bitte füllen Sie das Feld «' + text[0] + '» mit einer gültigen E-Mail Adresse aus.</label>');
                    }
                    else {
                        $label.before('<label class="error" for="' + name + '">Bitte füllen Sie das Feld «' + text[0] + '» aus.</label>');
                    }
                    $this.attr('aria-invalide', 'true');
                }
            }
        });
        if(error) {
            return false;
        }
        return true;
    });
    
    /** mehr Links **/
    $('a.tt_highlights_list_more, a.tt_news_topnews_list_more, a.tt_news_sport_list_more, a.tt_news_nachrichten_list_more').parent('p').hide();
    if( $('.tt_news_highlight_latest').length) {
    	$('a.tt_highlights_list_more').parent('p').show();	
	}
	if( $('.tt_news_topnews_latest').length) {
    	$('a.tt_news_topnews_list_more').parent('p').show();	
	}
	if( $('.tt_news_sport_latest').length) {
    	$('a.tt_news_sport_list_more').parent('p').show();	
	}
	if( $('.tt_news_sport_list').length) {
    	$('a.tt_news_sport_list_more').parent('p').show();	
	}
	if( $('.tt_news_nachrichten_latest').length) {
    	$('a.tt_news_nachrichten_list_more').parent('p').show();	
	}
    
    $('#nav form label').labelOver('over');
    
    /* Programplan */
	$(".programmplan h4").click(function() {
		$this = $(this);
		$this.parent().siblings().removeClass('active');
		$this.parent().addClass('active');
	});
		
	/** Box-Shadow für IE **/
	if ($.browser.msie) {
		//.page
		var $elm = $(".page");
		var pos = $elm.position();
		if($.browser.version <= 6) {
			$elm.css({'position': 'absolute', 'top': 0, 'left': 0, 'z-index': 2, 'width': 980 + "px"});
		}
		else {
			$elm.css({'position': 'absolute', 'top': 0, 'left': 0, 'z-index': 2, 'width': 960 + "px"});			
		}
		$elm.after("<div class='ie-shadow'></div>");
		$(".ie-shadow").width($elm.width() + 10).height($elm.height() + 10).css("left", (pos.left - 10) + "px").css("top",(pos.top - 10) + "px");		
	}
	$('#col3_content .floatbox .subcolumns').parent('.floatbox').css({'border': 0, 'padding': 0});
    
});

/** Labels über Inputfeld **/
(function($) {
    $.fn.labelOver = function(overClass) {
    	return this.each(function(){
    		var label = jQuery(this);
    		var f = label.attr('for');
    		if (f) {
    			var input = jQuery('#' + f);
    			
    			this.hide = function() {
    			  label.css({ textIndent: -10000 })
    			}
    			
    			this.show = function() {
    			  if (input.val() == '') label.css({ textIndent: 0 })
    			}
    
    			// handlers
    			input.focus(this.hide);
    			input.blur(this.show);
    		    label.addClass(overClass).click(function(){ input.focus() });
    			
    			if (input.val() != '') this.hide(); 
    		}
    	})
    }
})(jQuery);
