var IEPNGFix = window.IEPNGFix || {};

// Run whem DOM-Rady
$(document).ready(function() {
    addCorners();
    addOddEven();
    IE6PNGFIX();
    $("div.modal-wrap").css("display", "none");
});

// View terms modal
$("a.view-terms").click(function() {
    $("div.modal-wrap").css("display", "block");
});

// Close terms modal
$("a.close-terms").click(function() {
    $("div.modal-wrap").css("display", "none");
});


// Add corners to all divs with class rc (R)ounded (C)orners
function addCorners() {
    $("div.rc-1").wrap('<div class="box box-1"><div class="c">');
    $("div.rc-2").wrap('<div class="box box-2"><div class="c">');
	$('div.c').prepend('<div class="t"></div>');
	$('div.box').append('<div class="b"><div></div></div>');
}

// Add odd/even classes on the dl/dt/dd list
function addOddEven() {
    $('dl dt:odd').addClass('odd');
    $('dl dt:even').addClass('even');
}

// IE6 Specific fix
function IE6PNGFIX() {
    if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) && document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule) {
        
        // Fix the rounded corner boxes
        document.styleSheets[0].addRule('div.c', 'behavior: url(/upload/landing/africa/htc/iepngfix.htc)');
        document.styleSheets[0].addRule('div.t', 'behavior: url(/upload/landing/africa/htc/iepngfix.htc)');
        document.styleSheets[0].addRule('div.b', 'behavior: url(/upload/landing/africa/htc/iepngfix.htc)');
        document.styleSheets[0].addRule('div.b div', 'behavior: url(/upload/landing/africa/htc/iepngfix.htc)');
        
        // Fix the graphic elements
        document.styleSheets[0].addRule('p.logo strong', 'behavior: url(/upload/landing/africa/htc/iepngfix.htc)');
        document.styleSheets[0].addRule('a.try-now', 'behavior: url(/upload/landing/africa/htc/iepngfix.htc)');
        document.styleSheets[0].addRule('p.payment-methods', 'behavior: url(/upload/landing/africa/htc/iepngfix.htc)');
        
        // One done fixing PNG's - Repoistion the graphics that are placed outside the boxes
        positionSplashes();
    }
}

// Position graphic elements positioned outside the box
function positionSplashes() {

    //  Get the height of the main content container and force it inline
    var main = $("div.main-content");
    var mainheight = main.height();
    $(main).css("height", mainheight);
    
    // Get the position of the try-now splash in co-ordinates
    var trynow = $("a.try-now");
    var trynow_position = trynow.position();
    
    // Get the position of the call-to-action
    var lowestrate = $("a.lowest-rate");
    var lowestrate_position = trynow.position();
    
    // Move the try-now splash in the DOM and re-position it with absolute
    $(trynow).remove().insertAfter(main.parent());
    $(trynow).css("position", "absolute");
    $(trynow).css("top", trynow_position.top);
    $(trynow).css("left", trynow_position.left);

    // Move the try-now splash in the DOM and re-position it with absolute
    // var calltoaction = $("div.call-to-action");
    // $(lowestrate).remove().insertAfter(calltoaction.parent());
}