﻿

$(document).ready(function() { 

    Setup();
    
}); 


function Setup(){

    /* Resize the free gift tabs */    
    $(".FreeGiftTab").css({width:(978-$(".HomeFreeGifts .Tabs").width())});
    
    /* Add rollovers to free gift tabs */    
    $(".HomeFreeGifts .Tabs a").click(
        function(){
            $(".HomeFreeGifts .Tabs a").removeClass("TabOn").addClass("Tab");
            $(this).removeClass("Tab").addClass("TabOn");
        }
    );
    
    $(".HomeFreeGifts .Tab").hover(
      function () {
        $(this).removeClass("Tab").addClass("TabActive");
      }, 
      function () {
        $(this).removeClass("TabActive").addClass("Tab");
      }
    );
    
    $(".HomeFreeGifts .Tabs a:eq(0)").addClass("TabOn");
    
    /* Add rollovers to other buttons */    
    $(".BtnAllMatching").hover(
      function () {
        $(this).removeClass("BtnAllMatching").addClass("BtnAllMatchingHover");
      }, 
      function () {
        $(this).removeClass("BtnAllMatchingHover").addClass("BtnAllMatching");
      }
    );
    
    $(".BtnAll6Month").hover(
      function () {
        $(this).removeClass("BtnAll6Month").addClass("BtnAll6MonthHover");
      }, 
      function () {
        $(this).removeClass("BtnAll6MonthHover").addClass("BtnAll6Month");
      }
    );
    
    $(".BtnAllRecent").hover(
      function () {
        $(this).removeClass("BtnAllRecent").addClass("BtnAllRecentHover");
      }, 
      function () {
        $(this).removeClass("BtnAllRecentHover").addClass("BtnAllRecent");
      }
    );
    
    $.blockUI.defaults = { 
        overlayCSS:  { backgroundColor: 'White', opacity: '0.85' }
    };
    
}
                
function GetFreeGift(myGiftID){
    
    $(".Block_FG").block("<img src='i/loading.gif' alt=''/>");
        
    //get details
    $.getJSON("Data.ashx", { "action": "FreeGiftDetails", "GiftID": myGiftID, "Refresh": new Date().getTime() }, function(data){
                  
        $.each(data, function(entryIndex, entry){        
            $('#lbl_freegift').html(entry["0"]);
            $('#img_freegift').attr("src", files + entry["1"]);
            $('.Details').css("display", "block")
        });
        
    });
        
    //get handsets
    $.getJSON("Data.ashx", { "action": "FreeGiftHandsets", "GiftID": myGiftID, "Refresh": new Date().getTime() }, function(data){
    
        var element = $('#lbl_freegifts');
        var output = ""
        
        output += "<ul class='Items'>"; 
                                          
        $.each(data, function(entryIndex, entry){
            output += "<li>";
            output += "<div><a href='handset-" + entry["0"] + "-" + url_encode(entry["1"]) + "-" + url_encode(entry["2"]) + ".aspx?gift=" + myGiftID + "'><img src='" + files_central + entry["3"] + "' alt='" + entry["1"] + " " + entry["2"] + "' class='reflect rheight35 ropacity40' /></a></div>";
            output += "<div class='Label'>" + entry["2"] + "</div>";
            output += "</li>";
        });
        
        output += "</ul>"; 
        
        element.empty();
        element.append(output); 
                        
        ResetCarousel();
        
        $(".Block_FG").unblock();
                        
    });
    
    //set link
    $("#link_freegifts").attr("href", "handsetsearch.aspx?gift=" + myGiftID);
        
    
}
                
function GetOtherHandsets(){
    
    $(".BlockOther").block("<img src='i/loading.gif' alt=''/>");
        
    $.getJSON("Data.ashx", { "action": "FreeLineRentalHandsets", "Refresh": new Date().getTime() }, function(data){
    
        var element = $('#lbl_freelinerental');
        var output = ""
        
        output += "<ul class='Items'>"; 
                                          
        $.each(data, function(entryIndex, entry){
            output += "<li>";
            output += "<div><a href='handset-" + entry["0"] + "-" + entry["1"].replace(" ", "-") + "-" + entry["2"].replace(" ", "-") + ".aspx?linerental=6'><img src='" + files_central + entry["3"] + "' alt='" + entry["1"] + " " + entry["2"] + "' class='reflect rheight35 ropacity40' /></a></div>";
            output += "<div class='Label'>" + entry["2"] + "</div>";
            output += "</li>";
        });
        
        output += "</ul>"; 
        
        element.empty();
        element.append(output); 
                        
    });
        
    $.getJSON("Data.ashx", { "action": "LatestHandsets", "Refresh": new Date().getTime() }, function(data){
    
        var element = $('#lbl_latest');
        var output = ""
        
        output += "<ul class='Items'>"; 
                                          
        $.each(data, function(entryIndex, entry){
            output += "<li>";
            output += "<div><a href='handset-" + entry["0"] + "-" + entry["1"].replace(" ", "-") + "-" + entry["2"].replace(" ", "-") + ".aspx'><img src='" + files_central + entry["3"] + "' alt='" + entry["1"] + " " + entry["2"] + "' class='reflect rheight35 ropacity40' /></a></div>";
            output += "<div class='Label'>" + entry["2"] + "</div>";
            output += "</li>";
        });
        
        output += "</ul>"; 
        
        element.empty();
        element.append(output); 
    
        $(".BlockOther").unblock();
                        
    });
                        
    ResetCarousel();
    
}