
$(document).ready(function (){
    
      banner_width = $('a[id="banner_box"]').attr('dlgwidth'); 
      banner_height = $('a[id="banner_box"]').attr('dlgheight'); 
      $("a[rel='banner_box']").colorbox({ innerWidth:parseInt(banner_width)+25, innerHeight:parseInt(banner_height)+10});
      
      
      $('a[id^="day"]').each(function()
      {
            $(this).qtip({
             content: getEvent($(this).attr("id")),
             position: {
                corner: {
                   target: 'bottomMiddle', 
                   tooltip: 'topMiddle'
                },
                adjust: {
                   screen: true 
                }
             },
             show: { 
                when: 'click', 
                solo: true 
             },
             hide: { fixed: true, delay: 3000 },
             style: {
                tip: true, 
                border: {
                   width: 0,
                   radius: 4
                },
                name: 'light', 
                width: 350 
             }
          })
      });
});

function getEvent(elm){
    return $('div[id="'+elm+'"]').html();
}


function calendarNavigate(tclass){
    url = $("."+tclass).attr('href');
    //$('.calenda-bg').load(url);
    $(".calenda-bg").html('<img src="/themes/hotpot/images/web/tiny_loading.gif">');
    $.post(url,
      function(data){
        $(".calenda-bg").html('');
        $(".calenda-bg").html(data);
      }, "html");
}

function showLocationSearch(ftype){
    
    //$.fn.colorbox({href:'http://www.google.com', open:true, iframe:true, width:500, height:500}); 
    $.fn.colorbox({href:'/home/location/'+ftype, iframe:true, width:819, height:625}); 
    
    
}

function getBranch(zone,ftype){
    //alert(zone);
    select_branch = document.getElementById('sel_branch');
    var i;
    for(i=select_branch.options.length-1;i>=0;i--)
    {
        select_branch.remove(i);
    }
    
    url = '/home/getBranch/'+ftype+'/'+zone;
    $.post(url,
      function(data){
        
        var option=null;
        if (data != ""){
            branch = eval('(' + data + ')');
            
            for (i=0;i<branch.length;i++){
                px=branch[i];
                if(px["ID"]!=""){
                    option=document.createElement("option");
                    option.setAttribute("value",px["ID"]);
                    branch_name = px["BranchTitle"];
                    option.appendChild(document.createTextNode(branch_name.replace(/&amp;/g, "&")));
                    select_branch.appendChild(option);
                }
            }
        }else{
            option=document.createElement("option");
            option.setAttribute("value",'');
            option.appendChild(document.createTextNode("--- Not Found ---"));
            select_branch.appendChild(option);
        }
        
        
      }, "jsson");
    
}

function getBranchData(){
    
    branch = $("#sel_branch").val();
    
    if (branch != ""){
        
        $("#bTitle").html("");
        $("#bLocation").html("");
        $("#bAddress").html("");
        $("#bTelephone").html("");
        
        
        url = '/home/getBranchData/'+branch;
        $.post(url,
          function(data){
            
            if (data != ""){
                branch = eval('(' + data + ')');
                
                $("#bTitle").html(branch[0]["BranchTitle"]);
                $("#bLocation").html(branch[0]["BranchLocation"]);
                $("#bAddress").html(branch[0]["BranchAddress"]);
                $("#bTelephone").html(branch[0]["BranchTelephone"]);
                setMap(branch[0]["BranchLatitude"],branch[0]["BranchLongitude"]);
            }
            
          }, "jsson");
    }
    
}

function setMap(lat,long){

    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("divMap"));
        var center = new GLatLng(lat,long);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(center, 16);
        ///---------------------Create our "tiny" marker icon--------
        var tinyIcon = new GIcon();
        tinyIcon.image = "http://www.hotpot-restaurants.com/themes/hotpot/images/web/marker.png";
        //tinyIcon.image = "http://hotpot/themes/hotpot/images/web/marker.png";
        tinyIcon.iconSize = new GSize(48, 48);
        tinyIcon.iconAnchor = new GPoint(39, 47);
        //tinyIcon.infoWindowAnchor = new GPoint(100, 100);

        // Set up our GMarkerOptions object literal
        markerOptions = { icon:tinyIcon };

          var point1 = center;
          var myMarker = new GMarker(point1,markerOptions);
          //var myMarker = new GMarker(center, {draggable: true});
          map.addOverlay(myMarker);

    }

}


function showImage(psrc,pwidth,pheight){

    //psrc = psrc.replace("_thumb", "");
    //$.fn.colorbox({href:psrc+'?'+ran, width:parseInt(pwidth)+35, height:parseInt(pheight)+10});
    $.fn.colorbox({
    	href:psrc,
		width:430, 
		height:325
    });
}

function getContactMap(ftype){

    $.fn.colorbox({href:'/contact-us/map/'+ftype, iframe:true, width:500, height:450}); 
    
}
