﻿//floating image box for listing
function LoadThumb(index,type) {
  var e = '#thumb' + type + index;
  $(e).bind("mouseenter", function() {
    $('<div class="float-box-l"></div>').appendTo(this).fadeIn(700);
    $('<div class="float-box-r"></div>').html('').appendTo(this).fadeIn(700);
    $.ajax({
    url: '/condominiums/ajaxsvr/svr_imagethumb.aspx',
      type: 'POST',
      data: 'pid=' + index,
      datatype: 'application/xml',
      timeout: 100000,
      error: function(err) {
        ('.float-box-r').html("Error loading help");
      },
      success: function(xml) {
        $('.float-box-r').empty();
        $('.float-box-e').empty();
        $(xml).find('image').each(function() {
        $('<div class="float-box-e"></div>').appendTo($('.float-box-r')).loadImage('http://pictures.iproperty.com.my/imglib/realtors/120/', $(this).find('desc').text(), {
            filename: $(this).find('fn').text()
          },
                     {
                       height: '90',
                       width: '120',
                       bgColor: '#FFF',
                       color: '#000'
                     }
                 );
        });
      }
    });
  }).bind("mouseleave", function() {
    $(this).empty();
  });
}

function LoadThumbCondo(index) {
  //$('.float-body').css('background', 'url(images/icons.gif) no-repeat -60px 0px');
  var e = '#thumb' + index;
  $(e).bind("mouseenter", function() {
    $('<div class="float-box-ds-l"></div>').appendTo(this).fadeIn(700);
    $('<div class="float-box-ds-r"></div>').html('').appendTo(this).fadeIn(700);
    $.ajax({
    url: '/condominiums/ajaxsvr/svr_imagethumbstate.aspx',
      type: 'POST',
      data: 'bid=' + index,
      datatype: 'application/xml',
      timeout: 100000,
      error: function(err) {
        ('.float-box-ds-r').html("Error loading help");
      },
      success: function(xml) {
        $('.float-box-ds-r').empty();
        $('.float-box-ds-e').empty();
        //            $('<span></span>').html("Total image uploaded: " + photocount).appendTo($('.float-box-r'));
        $(xml).find('image').each(function() {
        $('<div class="float-box-ds-e"></div>').appendTo($('.float-box-ds-r')).loadImage('http://pictures.iproperty.com.my/imglib/condominiums/120/', $(this).find('desc').text(), {
            filename: $(this).find('fn').text() 
          },
                     {
                       height: '90',
                       width: '120',
                       bgColor: '#FFF',
                       color: '#000'
                     }
                 );
        });
      }
    });
  }).bind("mouseleave", function() {
    $(this).empty();
  });
}

function RequestVideo(ID, Desc, t, total, f) {
  //alert(t + ":" + total);
  var x = 'http://www.youtube.com/v/' + ID;
  document.getElementById('m2').innerHTML = Desc;
  //alert(x);
  var so = new SWFObject(x, 'utube', '535px', '400px', '5.0.0', '#ffffff');
  so.addParam('wmode', 'transparent');
  so.useExpressInstall();
  so.write('utube');
  if (f == 0) {
    for (var i = 0; i <= total; i++) {
      if (i == t) {
        document.getElementById(i).style.border = 'Solid 5px #FFFFCC';
      } else {
        document.getElementById(i).style.border = 'Solid 5px #EEEEEE';
      }
    }
  }
}

//for image
$(document).ready(function() {

$('#mycarousel').jcarousel({ visible: 5, scroll: 5 });

});


$(document).ready(function() {
  $('#ddlState').change(function() {
    LoadCities($(this).val());
  });

  $('#ddlCities').change(function() {
    getCities($(this).val());
  });
});

//Ajax load drop down list : Cities
function LoadCities(stateCode) {
  var wait_note = "<option>Loading....</option>"; // wait message
  var zero_note = "<option>Sorry, No items match the options</option>";  // no item message

  $('#ddlCities').html(wait_note);
  $.ajax({
    url: '/condominiums/ajaxsvr/svr_loadCities.aspx',
    type: 'POST',
    data: 'ct=' + stateCode,
    datatype: 'text',
    timeout: 100000,
    error: function(err) {
      $('#ddlCities').html(zero_note);
      jAlert('This page has encountered an error that may prevent it from working correctly.', 'Error');
    },
    success: function(data) {
      $('#ddlCities').html(data);
      //$('#ddlCities').attr("selectedIndex", 0);
    }
  });
}

function getCities(CityID) {
  $("#hdCities").val(CityID);
}

function ClickThumb(pf) {
  var img1 = new Image()
  img1.src = pf
  var iwidth = img1.width
  var iheight = img1.height
  var z

  if (iwidth > iheight) {
    if (iwidth > 520) {
      z = iwidth / 520;
      iwidth = 520;
      iheight = iheight / z;
    }
  } else {
    if (iheight > 520) {
      z = iheight / 520;
      iheight = 520;
      iwidth = iwidth / z;
    }
  }
  document.getElementById('GoTo').href = '/openMainPhoto.aspx?sPic=' + pf;
  document.getElementById('_ctl0_imgHouse').src = pf;
  document.getElementById('_ctl0_imgHouse').width = iwidth;
  document.getElementById('_ctl0_imgHouse').height = iheight;
}

function picResize(myImage, obj, maxh, maxw) {
    var img1 = new Image()
    var val = myImage
    img1.src = val
    var iwidth = img1.width
    var iheight = img1.height

    var ratio = maxh / maxw;
    if (iheight / iwidth > ratio) {
        // height is the problem
        if (iheight > maxh) {
            iwidth = Math.round(iwidth * (maxh / iheight));
            iheight = maxh;
        }
    } else {
        // width is the problem
        if (iwidth > maxw) {
            iheight = Math.round(iheight * (maxw / iwidth));
            iwidth = maxw;
        }
    }

    obj.height = iheight;
    obj.width = iwidth;
}
