﻿$(document).ready(function () {
    var param = getParameterByName("ref");
    if (param != "") $.cookie("ref", param, { path: "/", expires: 200 });
    if ($.cookie("ref") != undefined) { WebService.Savepage($.cookie("ref"), window.location.href, $("#ctl00_hidip").val()); }
    var current = $.cookie("current") != "" ? $.cookie("current") : 0;
    $(".accordion").accordion({ autoHeight: true, active: eval(current) + 0, change: function (event, ui) {
        var index = $(this).find("h3").index(ui.newHeader[0]);
        $.cookie("current", index, { path: "/" });
    }
    });
    $("#accordion div").css({ margin: "0px", padding: "4px" });
    $("#zoomin").click(function () {
        var fontsize = $("#content table td:first").css("font-size");
        fontsize = fontsize.split("px");
        fontsize = eval(fontsize[0]) + 2;
        $("#content").css({ "font-size": fontsize + "px" });
    });
    $("#zoomout").click(function () {
        var fontsize = $("#content").css("font-size");
        fontsize = fontsize.split("px");
        fontsize = eval(fontsize[0]) - 2;
        $("#content").css({ "font-size": fontsize + "px" });
    });

    $(".rapidshare").each(function () { var link = $(this).html(); link = "<a href='http://rapidshare.com/" + link + "' target='_blank'>http://rapidshare.com/" + link + "</a>"; $(this).html(link); });
    $(".tabs").tabs();
});

function announceFriends(code) {    
    if ($("#dialog").length == 0) {
        $(document.body).append("<div id='dialog' title='Send this page to a friend'></div>");
        $("#dialog").dialog({ width: 480, height: 280, autoOpen: false, modal: true, resizable: false, buttons: { "OK": function() { if ($("#frms2f").validate().form()) { $("#frms2f").ajaxSubmit({ success: function(data) { if(data=="true")$("#dialog").dialog('close'); } }); } } } });
        $("#dialog").load("/templates/s2f.html", function() { $("#hidcode").val(code); $("#dialog").dialog('open'); });                
    }
    else {
        $("#dialog").load("/templates/s2f.html", function() {
            $("#hidcode").val(code); $("#dialog").dialog('open');
            if (code != null) {
                $("#txthtml").val(code);
            }
        });
    }
}

function showHTML(code) {
    var sh;
    if ($("#dhtml").length == 0) {
        $(document.body).append("<div id='dhtml' title='HTML Renderer >> "+code+"'></div>");
        $("#dhtml").dialog({ width: 800, height: 500, autoOpen: false, resizable: true });
        /*
            resizeStart: function(event, ui) { sh = $(this).height(); },
            resizeStop: function(event, ui) { sh = $(this).height() - sh; $("#result").height($("#result").height() + sh); }
        */
        $("#dhtml").load("/templates/htmlprev.html", function() {
            $("#dhtml").dialog('open');
            if (code != "") {
                $.get("/templates/" + code + ".html", function(data) { $("#txthtml").val(data); });                
            }
            $("#txthtml").css("font-family", "Courier");
        });
    }
    else {
        $("#dhtml").load("/templates/htmlprev.html", function() {
            $("#dhtml").dialog('open');
            if (code != "") {
                $.get("/templates/" + code + ".html", function(data) { $("#txthtml").val(data); });                
            }
            $("#txthtml").css("font-family", "Courier");
        });
    }

}

$.extend({
    jYoutube: function(url, size) {
        if (url === null) { return ""; }

        size = (size === null) ? "big" : size;
        var vid;
        var results;

        results = url.match("[\\?&]v=([^&#]*)");

        vid = (results === null) ? url : results[1];

        if (size == "small") {
            return "http://img.youtube.com/vi/" + vid + "/2.jpg";
        } else {
            return "http://img.youtube.com/vi/" + vid + "/0.jpg";
        }
    }
});

jQuery.fn.youtube = function() {
    lnk = $(this).attr("id");
    var a = $("<object></object>").attr("type", "application/x-shockwave-flash").attr("width", "400").attr("height", "329").attr("data", "http://www.youtube.com/v/" + lnk);
    var p = '<param name="movie" value="http://www.youtube.com/v/' + lnk + '" /><param name="wmode" value="transparent" />';
    $(a).html(p);
    $(this).html(a);
}

$(document).ready(function() {
    $(".youtube").each(function() {
        $("#" + $(this).attr("id")).youtube();
    });
});
