﻿$(document).ready(init);

function init() {
   
   createTabs();
   activeTab(0);
}

function createTabs() {
    $("ul.Tagtop li").each(function(index) {
        $(this).wrapInner("<a href='#'></a>")
            .children("a").click(function() { return activeTab(index); });
    });
}

function activeTab(tabId) {
    $("ul.Tagtop li").removeClass("active").eq(tabId).toggleClass("active");
    $("div.DiscoverContent").hide().eq(tabId).show();
    $("div.HotelList").hide().eq(tabId).show();

    if (tabId == 0)
        getData(2);
    else
        getData(1);
    
    return false;
}


function getData(type) {
    $.ajax({
        data: { type: type }
        , type: "POST"
        , url: "/Services/HotelApartmentService.ashx"
        , timeout: 30000
        , cache: false
        , dataType: "json"
        , success: function(data, status) {
            displayData(type, data);
        }
        , error: function(request, status, error) {

        }
        , complete: function(request, status) {
          
        }
    });
}

function displayData(type, data) {

    // attach the template
    $("#result" + type).setTemplateElement("template" + type);
    
    // process the template
    $("#result" + type).processTemplate(data);
}