$(document).ready(function () {
    $(".ResultsRhymes .c33l, .ResultsRhymes .c33r").mouseenter(function (e) {
        $(this).css({ "width": "43%" });
        $(".ResultsRhymes .c33l, .ResultsRhymes .c33r").not(this).css({ "width": "27.5%" });
    });
    $(".ResultsRhymes").mouseleave(function (e) {
        $(".ResultsRhymes .c33l, .ResultsRhymes .c33r").css({ "width": "33.3%" })
    });

    var FurtherLink = $("<a target='_blank' class='Further'></a>");
    $(".Result").each(function () {
        var EncodedWord = encodeURIComponent($(".Word", this).text().replace(/^\s+|\s+$/g, ""));
        $(FurtherLink).clone().addClass("Wikipedia").attr("href", "http://de.wikipedia.org/wiki/" + EncodedWord).appendTo(this);
        $(FurtherLink).clone().addClass("Duden").attr("href", "http://www.duden.de/suchen/dudenonline/" + EncodedWord).appendTo(this);
        $(FurtherLink).clone().addClass("Dict").attr("href", "http://www.dict.cc/?s=" + EncodedWord).appendTo(this);
        $(FurtherLink).clone().addClass("Synonym").attr("href", "http://www.woerterbuch.info/deutsch-englisch/synonym/" + EncodedWord + ".php").appendTo(this);
    });

    $(".Result").mouseenter(function () { $(this).children(".Further").show(); })
		.mouseleave(function () { $(this).children(".Further").hide(); });

    /*$(".Rhyme").each(function (i, e) {
        var Temp = $(this).text().trim();
        $(this).text("");
        for (c = 0; c < Temp.length; c++)
            $(this).append("<a href='/Reimt-auf/" + Temp.substr(c) + "' Mark='" + Temp.substr(c) + "' target='_self'>" + Temp.charAt(c) + "</a>");
        $(this).append("<div class='Mark' />").children("a").hover(function () {
            $(this).parent().children(".Mark").text($(this).attr("Mark"));
        });
    });*/
		$(".Rhyme a").hover(function() {
			$(this).parent().children(".Mark").text($(this).attr("mark"));
		});

    $(".AddWordsLink").fancybox({ 'type': 'iframe', 'width': 380, 'height': 285, 'scrolling': 'no' });
    $(".ManageWordsLink").fancybox({ "type": "iframe" });
    $(".AbuseMessageLink").live('click', function(e) { e.preventDefault(); $.fancybox($(this).attr("href"),{ "type": "iframe" }); });

    // Add Classes for Login Style
    $(".BoxLoginContent input[id$='Login_DNN_txtUsername']").addClass("LoginUsername");
    $(".BoxLoginContent input[id$='Login_DNN_txtPassword']").addClass("LoginPassword");
    $(".BoxLoginContent input[id$='Login_DNN_cmdLogin']").addClass("LoginButton").val("");
    $(".BoxLoginContent input[id$='chkCookie']").addClass("LoginRemember").parent().insertBefore($(".LoginButton"));
    $(".BoxLoginContent a[id$='cmdRegister']").addClass("LoginRegister").insertAfter(".LoginButton");
    $(".BoxLoginContent a[id$='cmdPassword']").addClass("LoginForgotPassword");
    $(".BoxLoginContent>div>table>tbody>tr:eq(1), .BoxLoginContent>div>table>tbody>tr:eq(2), .BoxLoginContent>div>table>tbody>tr:eq(3), .BoxLoginContent>div>table>tbody>tr:eq(4)").css("display", "none");
    $(".BoxLoginContent>br").remove();
    $(".BoxLoginContent .LoginRemember").parent().after("<br />");

    // Hide Login Box and Inactive Overlays on Document click
    $(document).click(function () { $(".BoxLogin").fadeOut(); });
    $(".BoxLogin").click(function (e) { e.stopPropagation(); });

    $(".InactivePoemsOverlay").click(function () { $(this).fadeOut(); $(".InactiveRhymesOverlay").fadeIn() });
    $(".InactiveRhymesOverlay").click(function () { $(this).fadeOut(); $(".InactivePoemsOverlay").fadeIn() });

    $(".txtSearchRhymes").keydown(function (e) { if (e.keyCode == 13) { e.preventDefault(); RedirectRhymeUrl(); } $(".txtSearchPoem").val($(this).val()); });
    $(".txtSearchPoem").keydown(function (e) { if (e.keyCode == 13) { e.preventDefault(); window.location = $(".btnSearchPoems").attr("href"); } $(".txtSearchRhymes").val($(this).val()); });

    jQuery("a.TipPopupRhymes").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayColor': '#000',
        'overlayOpacity': 0.2,
        'showCloseButton': true,
        'titleShow': false,
        'scrolling': 'no'
    });

    jQuery(".Result .Further").fancybox({ 'type':'iframe', 'width':'80%', 'height':'80%' });
	
	jQuery(".Poem").click(function() {
		var AjaxUrl = jQuery(this).find(".PoemMoreLink").attr('href');
		
		$.fancybox.showActivity();
		
		/*$.ajax(jQuery(this).find(".PoemMoreLink").attr('href'), function(result) {
			$.fancybox(result);
		});*/
		var Url = "/Gedicht/tabid/74/mid/492/dnnprintmode/true/Default.aspx?SkinSrc=%5bG%5dSkins%2f_default%2fNo+Skin&ContainerSrc=%5bG%5dContainers%2f_default%2fNo+Container&PoemId=" + AjaxUrl.split('/')[2];
        $.ajax({
            data: "ApplicationName=" + "@(ApplicationName)",
            url: Url,
            success: function (data) {
								_gaq.push(['_trackPageview', Url]);
                LightBoxContent = $(".PoemDetail", data).html();
                delete data;
                $.fancybox(
			        LightBoxContent,
                    {
                        centerOnScroll: false,
												autoDimensions:false,
												width:600,
												height:600
                    }
		        );
            }
        });
	});
	
	
});

function ShowLogin()
{
	$(".BoxLogin").fadeIn();
}

function RedirectRhymeUrl()
{
	var Syllables = $(".cbSyllables").val().substr(8,1);
	var Url = "/Reimt-auf" + ($(".txtSearchRhymes").val() != "" ? "/" + $(".txtSearchRhymes").val() : "");
	Url += (Syllables != null) && (Syllables != "A") ? "/s/" + Syllables : "";
	window.location = Url;
}
/*
function RedirectPoemUrl(Category)
{
		Search = $(".txtSearchPoems").val();
		Type = $(".cbPoemSearchMode").val();

		string Url = "/Gedicht";
		Url += (Category != null) ? "/Kat/" + Category : "");
		if(!String.IsNullOrEmpty(Search))
		{
				Url += (Type == "reimt") ? "/reimt/" + Search : "";
				Url += (Type == "mit") ? "/mit/" + Search : "";
				Url += (Type == "von") ? "/von/" + Search : "";
		}
		Url += (!String.IsNullOrEmpty(Page) && (Page != "1")) ? "/p/" + Page : "";
		Url += (!String.IsNullOrEmpty(State) ?  "/state/" + State : "");
		return Url;
}*/
