﻿$.ifixpng( '/system_images/pixel.gif' );
    $( '.png' ).ifixpng();
/*
    vars = {};
    params = {menu:false, wmode:'opaque', allowFullScreen:true};
    swfobject.embedSWF( 'flash/flashname.swf', 'ctv', 'width', 'height', 'version', '/flash/expressinstall.swf', vars, params );
*/

var amigos = {
    table : null,
    list : null, 
    
    init : function () {
        this.table = $("table.amigos");
        if (this.table.length === 0) { return; }
        this.buildList();    
    },
    buildList : function () {
        var nr = 1;
        this.table.each(function() {
            var countries, list;
            list = "<form style=\"height: 1%;\" action=\"\" method=\"post\" ><select name=\"showamigosprice" + nr + "\" class=\"amigoslist\">";
            countries = $(this).find("tr").find("td:first-child");
            countries.each(function() {
                list += "<option value=\"";
                list += $(this).html() + "|" + $(this).next().html() + "|" + $(this).next().next().html() + "|" + $(this).next().next().next().html() + "|" + $(this).next().next().next().next().html(); 
                list += "\">";
                list += $(this).html();
                list += "</option>";
            });
            list += "</select></form>";
            list += "<div class=\"showamigosprice" + nr + "\"></div>";
            $(this).after(list);
            $(this).remove();
            nr += 1;
        });
        this.activateList();
    },
    activateList : function () {
        this.list = $("select.amigoslist");
        this.list.each(function() {
            var showname = "div." + $(this).attr("name");
            $(this).change(function() {
                var result, resulttxt;
                result  = $(this).find("option:selected").val();
                result = result.split("|");
                if (result[0] == "Land") {
                    resulttxt = "<p>V\u00E4lj ett land i rullistan ovan</p>";
                } else {
                    resulttxt = "<p>";
                    resulttxt += "<strong>" + result[0] + "</strong><br />Samtal " + result[1] + "/min";
                   /* if (result[3] != "") {
                        resulttxt += "*";
                    }*/
                    resulttxt += "<br />\u00D6ppningsavgift " + result[2] ;
                    /*if (result[3] != "") {
                        resulttxt += "<br /><br />*TIPS: Tankar du v\u00E4rdebeviset AMIGOS betalar du " + result[3] + "/min. Erbjudandet g\u00E4ller 19 maj-31 aug 2008.";
                    }*/
                    resulttxt += "</p>";
                }
                $(showname).html(resulttxt);
            });
        });
    }
};

function clearText(ele) {
    var checkfor = $(ele).attr("title");
    if ($(ele).data("checkempty"))
        checkfor += "*";
    if ($(ele).attr("value") == checkfor) {
        $(ele).attr("value", "");
    }
}
function resetText(ele) {
    var checkfor = $(ele).attr("title");
    if ($(ele).data("checkempty"))
        checkfor += "*";
    if ($(ele).attr("value") == "") {
        $(ele).attr("value", checkfor)
    }
}
var cardValue;
function changeValue(value) {
    cardValue = value;
    $("#top-sum").html(value + " kr");
    $("#amount").html("<br />" + value + " kr");
    var span = $("#paymethod-amount span:first-child");
    $("#sum-amount span:first-child").html(parseFloat(span.html()) + parseFloat(value));
}
function hideNewNumber() {
    $("#txt-box-container").addClass("new-number");
    $("#txt-box-container").removeClass("old-number");

}
function showNewNumber() {
    $("#txt-box-container").removeClass("new-number");
    $("#txt-box-container").addClass("old-number");
}

function paymethod(ele) {
    
    var text = $(ele).siblings("span");
    $("#paymethod").html(text.html());
    var change = $("#paymethod-amount div span:first-child");
    
    change.html($(ele).attr("value"));
    
    changeValue(cardValue);

}
function hideAddress() {
    $("#info-text").removeClass("hidden");
    $("#info-text").addClass("visible");
    $("#third-column-text-box").addClass("hidden");
    $("#third-column-text-box").removeClass("visible");
}
function showAddress() {
    $("#info-text").removeClass("visible");
    $("#info-text").addClass("hidden");
    $("#third-column-text-box").addClass("visible");
    $("#third-column-text-box").removeClass("hidden");
}
$(document).ready(function() {
    amigos.init();
    cardValue = '100';
    
});