var $j = jQuery.noConflict();




//Formular Enter-Key abfangen
(function($) {
    jQuery.fn.enterToTab = function() {
        return this.each(function() {
            $(this).bind('keypress', function(event) {
                if (event.keyCode == '13') {
                    event.preventDefault();
                    var list = $(":focusable");
                    list.eq(list.index(this)+1).focus().select();
                }
            });
        });
    }

    $.extend($.expr[':'], {
        focusable: function(element) {
            var nodeName = element.nodeName.toLowerCase(),
                tabIndex = $.attr(element, 'tabindex');
                return (/input|select|textarea|button|object/.test(nodeName)
                     ? !element.disabled
                    : 'a' == nodeName || 'area' == nodeName
                    ? element.href || !isNaN(tabIndex)
                    : !isNaN(tabIndex))
                    // the element and all of its ancestors must be visible
                    // the browser may report that the area is hidden
                    && !$(element)['area' == nodeName ? 'parents' : 'closest'](':hidden').length;
        }
    });
})(jQuery);









jQuery(document).ready(function () {

    //Komitee-Tool: pre-check checkboxes
    //jQuery("#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneContextWidgets_FDPZCommiteeToolWidgetExtended_editForm_formElem_form_Options_0").attr('checked', 'yes');
    //jQuery("#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneContextWidgets_FDPZCommiteeToolWidgetExtended_editForm_formElem_form_Options_1").attr('checked', 'yes');

    //Formular-Felder Validierung: rote Hervorhebung
    jQuery('.EditingFormErrorLabel').css("display", "none").parent().addClass("errorForm");

    //FlipbookWidget hovereffekt
    jQuery(".flipbook_hover").hide();

    jQuery(".flipbook_hover_div").hover(function () {
        jQuery(this).find(".flipbook_hover").stop(true, true).fadeIn(500);
    },
	function () {
	    jQuery(this).find(".flipbook_hover").stop(true, true).fadeOut(500);
	});



    //blendet Zitat-Balken aus, wenn kein Zitat angegeben wurde.
    jQuery("#container_slogan:empty").hide();

    // remove font-size
    jQuery("#container_content_padding p span").css({ "font-size": "" });
    jQuery("#container_content_padding div span").css({ "font-size": "" });
    jQuery("#container_context_padding p span").css({ "font-size": "" });
    jQuery("#container_context_padding div span").css({ "font-size": "" });

    jQuery('.bx_slider').bxSlider({
        auto: true,
        autoControls: false,
        autoHover: true,
        pager: false,
        controls: false,
        pause: 5000,
        speed: 800
    });

    jQuery(".back").click(function () {
        if (history.length) {
            //There is history to go back to
            history.go(-1);
            return false;
        }
    });
    jQuery("input").enterToTab();
    /*toggle for payment boxes*/

    // add target attribute to feed link because its generated in sourcecode
    jQuery(".FeedLink").attr("target", "_blank");

    // 6
    jQuery(".table-default-alt tr:odd").css("background", "#f3f3f3");

    // 7
    jQuery(".table-default-horizontal td").css("border-bottom", "solid 1px #aaa");

    // 8
    jQuery(".table-default-vertical td").css("border-right", "solid 1px #aaa");

    // 7
    jQuery(".table-default-headleft-horizontal td").css("border-bottom", "solid 1px #aaa");

    // 8
    jQuery(".table-default-headleft-alt tr:odd").css("background", "#f3f3f3");

    // 9 
    jQuery(".table-default-head-horizontal td").css("border-bottom", "solid 1px #aaa");


    // 10
    jQuery(".table-default-head-alt tr:odd").css("background", "#f3f3f3");

    // 11
    jQuery(".table-default-headboth-horizontal tr td").css("border-bottom", "solid 1px #aaa");

    // 12
    jQuery(".table-default-headboth-alt tr:odd").css("background", "#f3f3f3");

    // remove first th background if headings are left and top
    jQuery(".table-default-headboth-alt th:first").css("background", "none");


    jQuery("#openSmartVoteProfile").fancybox({
        'margin': 0,
        'scrolling': 'auto',
        'padding': 0,
        'width': 797,
        'height': 580,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'titleShow': false
    });

    jQuery("h2:empty").hide();
    jQuery(".list-item p:empty").hide();

    //jQuery(".fbConnectWidgetTopmost").css("width","340px");
    /*Table formating */
    jQuery(".tbl_siteversions tr:odd td").css("background", "#F7F7F7");
    jQuery(".tbl_siteversions tr.title td").css("background", "#f1f1f1");

    //jQuery(".list-item:last").css("border", "none");


    /*Blog formating*/
    jQuery(".comments .list-item:even").css("background", "#f3f3f3");
    jQuery(".comments .list-item:last").css("border", "none");

    Cufon.set('fontFamily', 'Linotype Univers 420 Condensed').replace('h1,h2, #bluetitle_content,.FirstLine,#container_slogan');
    Cufon.set('fontFamily', 'Linotype Univers 320 CnLight').replace('.SecondLine');

    jQuery(".Calendar table td:first").css("background-color", "#e4e4e4").css("color", "#848484");
    jQuery(".Calendar table:first a").attr("style", "color: #848484").parent().prev().attr("style", "width: 70%; color: #848484;")

    jQuery(".mainnavi a:last").css("border-right", "none");

    // Stats bar for poll results
    /*jQuery(".PollCount").each( function(e) {
    el = jQuery(this);
    
    var xwidth = el.html();
    var div1 = "<div style='color: #fff; text-align: center; padding-top: 2px; width:"+ xwidth +"; height: 20px; background: #074EA1;'>"+ el.html() +"</div>";
    
    if ( el.html() == "0%")
    var div1 = "<div style='color: #848484; text-align: center; padding-top: 2px; width: 1%; height: 20px;'>"+ el.html() +"</div>";
    
	
    el.prev().html( div1);
    el.html("");

    });*/

    /*jQuery(".CntRatingContent").click( function() {
	
    alert("1");
    });*/

    // Edit Contribution un neccessary column removing
    // removes columns 2 and 4
    jQuery(".ContributionsGrid tr").each(function () {
        e = jQuery(this);
        e.find("td:eq(2), th:eq(2), td:eq(4), th:eq(4),td:eq(5), th:eq(5)").remove();
        e.find("th:eq(0)").html("");
        e.find("th:eq(2), td:eq(2)").css("text-align", "right");
        e.find("th:first").css("width", "15px");
    });
    jQuery(".ContributionsGrid tr:even").css("background", "#f3f3f3");

    var InfoLabel = "#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneContentText_ContributionList_list_editDoc_formElem_lblInfo";
    var SaveButtonID = "#plc_lt_zoneContent_PagePlaceholder_PagePlaceholder_lt_zoneContentText_ContributionList_list_btnList";

    jQuery(SaveButtonID).html("Zur&uuml;ck zur &Uuml;bersicht");

    // feuert postback um zürck zum menü zu gelangen bei edit contribution
    if (jQuery(InfoLabel).length > 0) {
        __doPostBack('plc$lt$zoneContent$PagePlaceholder$PagePlaceholder$lt$zoneContentText$ContributionList$list$btnList', '');

    }

    var icon = "/App_Themes/FDPZ/images/icon_gotop.gif";
    jQuery("a[href='#top']").css("background", "url(" + icon + ") bottom left no-repeat").css("padding-left", "20px");



    $j(".galleryPicture, .ContentGalleryPicture").fancybox({
        'overlayOpacity': 0.8,
        'overlayColor': '#000',
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'easingIn': 'easeOutBack',
        'easingOut': 'easeInBack',
        'titleShow': true,
        'type': 'image',
        'titlePosition': 'over'
    });

    $j(".LabelField").each(function () {
        var labelValue = $j(this).text();

        if (labelValue == "True") {
            $j(this).text("Ja");
        }

        if (labelValue == "False") {
            $j(this).text("Nein");
        }
    });


    function ReadCookie(cookieName) {
        var theCookie = "" + document.cookie;
        var ind = theCookie.indexOf(cookieName);
        if (ind == -1 || cookieName == "") return "";
        var ind1 = theCookie.indexOf(';', ind);
        if (ind1 == -1) ind1 = theCookie.length;
        return unescape(theCookie.substring(ind + cookieName.length + 1, ind1));
    }

    var cookie = ReadCookie('DocRated');

    function bluestars() {

        $j(".CntRatingResult").each(function (i) {
            var RatingStars = $j(this).parent().find("div.CntRatingContent");
            var CurrentRating = $j(this).text();
            $j(this).css("display", "none");
            var CurrentRatingValue = CurrentRating;

            for (i = 1; CurrentRatingValue > 0 && (i < 6); ++i) {

                if (CurrentRatingValue >= 1) {
                    RatingStars.find('[id$="Star_' + i + '"]').addClass("SelectedRatingStar");
                } else {
                    RatingStars.find('[id$="Star_' + i + '"]').addClass("SelectedRatingStarHalf");
                }

                if (cookie.indexOf(currentDocumentID) != -1) {
                    if (CurrentRatingValue >= 1) {
                        RatingStars.find('[id$="Star_' + i + '"]').addClass("BlueRatingStar").removeClass("filledRatingStar");
                    } else {
                        RatingStars.find('[id$="Star_' + i + '"]').addClass("BlueRatingStarHalf");
                    }
                }

                CurrentRatingValue = CurrentRatingValue - 1;
            }

        });
    };
    bluestars();
    /*
    setInterval(function() {
    var rating = $j("#rating_user_value").text();
    if (rating > 0) {
    $j(".CntRatingResult").each(function(i) {
    var RatingStars = $j(this).parent().find("div.CntRatingContent"); 
    for (i=1;rating > 0 && (i < 6);++i){
    if (rating >= 1){
    RatingStars.find('[id$="Star_' + i +'"]').addClass("SelectedRatingStar");
							
							 
    } else{
    RatingStars.find('[id$="Star_' + i +'"]').addClass("SelectedRatingStarHalf");
    }
    rating = rating - 1;
    }
				
    $j("#rating_user_value").text("");
    });
    }
    }, 50);
    */
    jQuery(".confirm_order").hide();

    jQuery(".lnk-payment-toggle").click(function () {
        jQuery(this).parent().next(".box-paymentmethod").not(":animated").slideToggle()	
		});
		
    jQuery('.toggle_invoice').toggle(function() {
		jQuery(".confirm_order").show();
		}, function() {
		jQuery(".confirm_order").hide();
	});
		
    

});



jQuery.fn.DefaultValue = function(text){

    return this.each(function(){

		//Make sure we're dealing with text-based form fields
		if(this.type != 'text' && this.type != 'password' && this.type != 'textarea')
			return;	

		//Store field reference
		var fld_current=this;	

		//Set value initially if none are specified
        if(this.value=='') {
		this.value=text;		
		} else {			//Other value exists - ignore

			return;

		}

		

		//Remove values on focus

		$j(this).focus(function() {

			if(this.value==text || this.value=='')

				this.value='';

		});

		

		//Place values back on blur

		$j(this).blur(function() {

			if(this.value==text || this.value=='')

				this.value=text;

		});

		

		//Capture parent form submission

		//Remove field values that are still default

		$j(this).parents("form").each(function() {

			//Bind parent form submit

			$j(this).submit(function() {

				if(fld_current.value==text) {

					fld_current.value='';

				}

			});

		});

    });
};

//Content-Slide Widget jcarousel
jQuery(document).ready(function() {
    jQuery('.mycarousel').jcarousel({
        vertical: false,
		scroll: 1,
		visible: 1,
		auto: 7,
		wrap: "circular",
		buttonNextHTML: "<div><img src='/prev-horizontal.png' /></div>",
		buttonPrevHTML: "<div><img src='/next-horizontal.png' /></div>"
    });
});


// end secure mail
function JSrot13(text) {var text = text.replace(/%/, "@");var rot13text_rotated = ""; /* the function will return this string */;for (i = 1 ; i < (text.length + 1); i++) {k = text.charCodeAt(i-1);if (k >= 97 && k <= 109) {k = k + 13;} else if (k >= 110 && k <= 122) {k = k - 13;} else if (k >= 65 && k <= 77) {k = k + 13;} else if (k >= 78 && k <= 90) {k = k - 13;}rot13text_rotated = rot13text_rotated + String.fromCharCode(k);}return rot13text_rotated;}function Securemail(maillink){var maillink_output;maillink_output = JSrot13(maillink);location.href= 'mailto:' + maillink_output;}function displaymailaddress(linktext){var linktext_output;linktext_output = JSrot13(linktext);linktext_output = linktext_output.replace(/@/, "<span style='display:none'> *secure E-Mailaddress* <\/span>@");document.write(linktext_output);}
