/*
   =============================================
   Project:		Laforêt
   Version:		1.0.0
   Author:		Paulo Mendes
*/

function page_Print(d)
{
  setTimeout('window.print();', d);
}

function num_Validate(e, o)
{
  var evt = e ? e : window.event;
  var k;

  if (document.all)
    k = evt.keyCode;
  else
    k = evt.which;

  if (k >= 48 && k <= 57 || (k == 0 || k == 8))
    return true;
  else
    return false;
}

function num_Format(v)
{
  var c = '.';
  var d = '.';
  var pd = '';
  var dp = 3;

  try {
    v = v.replace(/\./g, '');
    
    if (v.length < 1) return '';
    
    if (parseInt(v) == 0) return '';
    
    if (v.length <= dp) return v;

    if (v.length > dp) {
      pd = d + v.substring(v.length - dp, v.length);
      v = v.substring(0, v.length - dp);
    }
    
    var r = new RegExp('(-?[0-9]+)([0-9]{3})');
    while (r.test(v)) {
      v = v.replace(r, '$1' + c + '$2');
    }
  }
  catch (e) {}
  
  return v + pd;
}

function img_Resize(obj, w, h)
{
  var t = new Image();
  t.src = obj.src;

  if ((t.width > w) || (t.height > h)) {
    var arw = w / parseFloat(t.width);
    var arh = h / parseFloat(t.height);

    var ar = Math.min(arh, arw);

    obj.width = parseInt(parseFloat(t.width) * ar);
    obj.height = parseInt(parseFloat(t.height) * ar);
  }
}

function img_Preview(obj, w, h)
{
  obj.onerror = null;

  obj.src = 'app_themes/iwebkit/propertyms/images/onerror/' + w + 'x' + h + '.gif';
}

String.prototype.replaceAt = function(i, c)
{
  return this.substr(0, i) + c + this.substr(i + 1 + c.length);
}

Array.prototype.indexOf = function(l)
{
  for (var i = 0; i < this.length; i++)
    if (this[i] == l)
      return i;

  return -1;
}

String.prototype.insertAt = function(i, c)
{
  return this.substr(0, i) + c + this.substr(i + 1);
}

$.fn.reset = function()
{
  return this.each(function() {
    var t = this.type, e = this.tagName.toLowerCase();

    if (e == 'div') return $(':input',this).reset();
  
    switch (t) {
      case 'text':
      case 'password':
      case 'textarea':
        this.value = '';
        break;
    
      case 'checkbox':
      case 'radio':
        this.checked = false;
        break;
  
      default:
        if (e == 'select') this.selectedIndex = -1;
    }
  });
};

function chk_Exclusive(e)
{
  var v = e.attr('checked');

  e.parent().parent().find(':checkbox').attr('checked', false);
  e.attr('checked', v);
}

function ddl_Clear(e)
{
  $(e).html('');
  $(e).attr('disabled', 'disabled');
}

function ddl_Disable(e)
{
  $(e).attr('disabled', 'disabled');
  $(e).get(0).selectedIndex = 0;
}

function ddl_Types(f, li, lang, wpro)
{
  var t = $(f + ' p.type select[name$="ddlType"]');
  ddl_Clear(t);

  var g = ['222', '225', '223', '', '224', '1532'];
  var id = (li > g.length) ? li : g[li];
  
  $(f + ' input[name$="qspGroup"]').attr('value', id);

  if (id == undefined) id = -1;

  if (id > 0) {
    $(t).append($('<option></option>').val(0).html(''));

    $.post('App_Handlers/GetTypes.ashx?pgrp=' + id + '&wpro=' + wpro + '&lang=' + lang, function(r) {
      $(t).html('');

      if (r != null && r != '') {
        var e = false;

        $(t).append($('<option></option>').val(0).html(''));
        $.each(r, function() {
          $(t).append($('<option></option>').val(this['DataValueField']).html(this['DataTextField']));
          e = true;
        });

        if (e) $(t).removeAttr('disabled');
      }
    });
  }
}

function bln_ToInteger(v)
{
  return (v == true) ? +v : '';
}

function ddl_Districts(f, wpro, wage, wdev, opt)
{
  var d = $(f + ' p.district select');
  var c = $(f + ' p.county select');
  var p = $(f + ' p.parish select');
  var z = $(f + ' p.zone select');

  ddl_Clear(d);
  ddl_Clear(c);
  ddl_Clear(p);
  ddl_Clear(z);

  $(d).append($('<option></option>').val(0).html(global_GetResource('Simple', 'Loading')));

  $.getJSON('App_Handlers/GetDistricts.ashx?wpro=' + bln_ToInteger(wpro) + '&wage=' + bln_ToInteger(wage) + '&wdev=' + bln_ToInteger(wdev), function(r) {
    $(d).html('');
    
    if (r != null && r != '') {      
      var e = false;

      if (opt) $(d).append($('<option></option>').val(0).html(''));

      $.each(r, function() {
        $(d).append($('<option></option>').val(this['DataValueField']).html(this['DataTextField']));
        e = true;
      });

      if (e) $(d).removeAttr('disabled');
    }
  });
}

function ddl_Counties(f, wpro, wage, wdev, opt)
{
  var d = $(f + ' p.district select');
  var c = $(f + ' p.county select');
  var p = $(f + ' p.parish select');
  var z = $(f + ' p.zone select');

  ddl_Clear(c);
  ddl_Clear(p);
  ddl_Clear(z);

  var id = $(d).val();

  if (id > 0) {
    $(c).append($('<option></option>').val(0).html(global_GetResource('Simple', 'Loading')));

    $.getJSON('App_Handlers/GetCounties.ashx?ldis=' + id + '&wpro=' + bln_ToInteger(wpro) + '&wage=' + bln_ToInteger(wage) + '&wdev=' + bln_ToInteger(wdev), function(r) {
      $(c).html('');
    
      if (r != null && r != '') {      
        var e = false;

        if (opt) $(c).append($('<option></option>').val(0).html(''));

        $.each(r, function() {
          $(c).append($('<option></option>').val(this['DataValueField']).html(this['DataTextField']));
          e = true;
        });

        if (e) $(c).removeAttr('disabled');
      }
    });
  }
}

function ddl_Parishes(f, wpro, wage, wdev, opt)
{
  var c = $(f + ' p.county select');
  var p = $(f + ' p.parish select');
  var z = $(f + ' p.zone select');

  ddl_Clear(p);
  ddl_Clear(z);

  var id = $(c).val();

  if (id > 0) {
    $(p).append($('<option></option>').val(0).html(global_GetResource('Simple', 'Loading')));

    $.getJSON('App_Handlers/GetParishes.ashx?lcty=' + id + '&wpro=' + bln_ToInteger(wpro) + '&wage=' + bln_ToInteger(wage) + '&wdev=' + bln_ToInteger(wdev), function(r) {
      $(p).html('');
      
      if (r != null && r != '') {
        var e = false;

        if (opt) $(p).append($('<option></option>').val(0).html(''));

        $.each(r, function() {
          $(p).append($('<option></option>').val(this['DataValueField']).html(this['DataTextField']));
          e = true;
        });
        
        if (e) $(p).removeAttr('disabled');
      }
    });
  }
}

function ddl_Zones(f, wpro, wage, wdev, opt)
{
  var p = $(f + ' p.parish select');
  var z = $(f + ' p.zone select');

  ddl_Clear(z);

  var id = $(p).val();

  if (id != 0 && id != '') {
    $(z).append($('<option></option>').val(0).html(global_GetResource('Simple', 'Loading')));

    $.getJSON('App_Handlers/GetZones.ashx?lpar=' + id + '&wpro=' + bln_ToInteger(wpro) + '&wage=' + bln_ToInteger(wage) + '&wdev=' + bln_ToInteger(wdev), function(r) {
      $(z).html('');

      if (r != null && r != '') {
        var e = false;

        if (opt) $(z).append($('<option></option>').val(0).html(''));

        $.each(r, function() {
          $(z).append($('<option></option>').val(this['DataValueField']).html(this['DataTextField']));
          e = true;
        });

        if (e) $(z).removeAttr('disabled');
      }
    });
  }
}

function ddl_TypologyMin(f, e)
{
  var max = $(f + 'select[name$="ddlTypologyMax"]');

  if (e[0].selectedIndex > 0 && max[0].selectedIndex > 0 && e[0].selectedIndex > max[0].selectedIndex)
    max[0].selectedIndex = e[0].selectedIndex;
}

function ddl_TypologyMax(f, e)
{
  var min = $(f + 'select[name$="ddlTypologyMin"]');

  if (min[0].selectedIndex > 0 && e[0].selectedIndex > 0 && e[0].selectedIndex < min[0].selectedIndex)
    min[0].selectedIndex = e[0].selectedIndex;
}

function tooltip_GetPosition(e)
{
  var l = 0;
  var t = 0;

  if (e.offsetParent) {
    l = e.offsetLeft;
    t = e.offsetTop;

    while (e = e.offsetParent) {
      l += e.offsetLeft;
      t += e.offsetTop;
    }
  }
  
  return [t, l];
}

function tooltip_OnLoad(e, m)
{
  var delay = 4500;
  var w = 211;
  var h = 81;

  var p = tooltip_GetPosition(e);

  var t = document.createElement('div');
  t.id = 'balloon';

  document.body.appendChild(t)

  if (!t.hasChildNodes()) {
    var d = document.createElement('div');
    with (d) {
      className = 'tooltip';
      style.top = parseInt(p[0] - h) + 'px';
      style.left = parseInt(p[1] - w) + 'px';
      innerHTML = '<div>' + m + '</div>';
    }
    t.appendChild(d);
    setTimeout('tooltip_OnUnload()', delay);
  }
}

function tooltip_OnUnload()
{
  document.body.removeChild(document.getElementById('balloon'));
}

function global_GetResource(f, n, c)
{
  var r;

  if (c == undefined) c = global_GetCulture();

  $.ajax({
    url: 'App_WebServices/Globalization.asmx/GetResouceByName',
    type: 'POST',
    async: false,
    data: 'File=' + f + '&Name=' + n + '&Culture=' + c,
    complete: function(j, t)
    {
      r = j.responseXML.getElementsByTagName('string')[0].firstChild.data;
    }
  });

  return r;
}

function element_Text(e, t)
{
  switch (e.attr('tagName').toLowerCase()) {
    case 'a':
      e.text(t);
      break;
    
    case 'input':
      e.val(t);
      break;
  }
}

function datetime_Now()
{
  var dt = new Date();

  var d = dt.getDate();
  var mt = dt.getMonth() + 1;
  var y = dt.getYear();

  var h = dt.getHours()
  var m = dt.getMinutes()

  return d + '-' + mt + '-' + y + ' ' + h + ':' + m;
}

function cookies_Get(n)
{
  return ($.cookies.get(n) != null) ? $.cookies.get(n).toString().split(';') : new Array();
}

function cookies_ExpiresAt()
{
  var e = new Date();
  e.setFullYear(e.getFullYear() + 1);

  return { expiresAt: e };
}

function cookies_Set(o, qsp, n, ra, rr)
{
  if (!$.cookies.test()) return false;

  var m = o.parent().find('input[name$="qspMethod"]');

  var e = o.parent().find('input[name$="' + qsp + '"]').attr('value');

  switch (m.attr('value').toLowerCase()) {
    case 'add':
      cookies_Add(e, n);
      element_Text(o, global_GetResource('List', rr));
      m.val('remove');
      break;

    case 'remove':
      cookies_Remove(e, n);
      element_Text(o, global_GetResource('List', ra));
      m.val('add');
      break;
  }
}

function cookies_Delete(n, a, v, p)
{
  for (var i = 0; i < a.length; i++) {
    var e = a[i].split(' ');

    if (e[p] == v) {
      a.splice(i, 1);
      break;
    }
  }

  (a.length > 0) ? $.cookies.set(n, a.join(';'), cookies_ExpiresAt()) : $.cookies.del(n);
}

function cookies_Add(e, n)
{
  var fav = cookies_Get(n);

  if (isNaN(e)) {
    var d = new Date();
    
    e = d.format("dd-mm-yyyy HH:MM") + ' ' + e;
  }
  
  fav.push(e);
  $.cookies.set(n, fav.join(';'), cookies_ExpiresAt());
}

function cookies_Remove(e, n)
{
  var fav = cookies_Get(n);

  if (isNaN(parseInt(e))) {
    cookies_Delete(n, fav, e, 2);    
    return;
  }

  cookies_Delete(n, fav, e, 0);

  fav = cookies_Get(n);
}

function doc_GetHeight()
{
  var h = 0;

  if (typeof (window.innerWidth) == 'number') {
    h = window.innerHeight;
  } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    h = document.documentElement.clientHeight;
  } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
    h = document.body.clientHeight;
  }

  return h;
}

function global_GetCulture()
{
  return $('#header .language a.current').parent().attr('class');
}





/*
   =============================================
   Group:       Search
   UserControl: ByReference.ascx
   Pane:        Left
*/
$(function()
{
  if ($('div.byref').length) $('div.byref input.textbox').toggleVal();
  
  $('div.byref input.button').click(function()
  {
    var e = $('div.byref input.textbox');

    if (e.val() == e.data('defText')) {
      tooltip_OnLoad(document.getElementById($(this).attr('id')), global_GetResource('ByReference', 'REQUIRED'));
      return false;
    }
    
    return true;
  });
});


/*
   =============================================
   Group:       Search
   UserControl: Simple.ascx
   Pane:        Left
*/
function simple_OnInit(grp, pl)
{
  var f = 'div.search ';

  var g = ['222', '225', '223', '-1', '224', '1532'];
  li = g.indexOf(grp);

  if (li == -1) li = 0;
  
  $(f + '#group li').removeClass('active');

  $(f + '#group li').removeClass('active');
  $(f + '#group li')[li].className += ' active';

  simple_OnLoad(li, false, pl, null);
}

function simple_OnLoad(li, bt, pl, e)
{
  var f = 'div.search ';

  var btn = $(f + 'input[class*="btnMoreDetailed"]');
  
  if (li != 3) {
    $(f + 'fieldset.development').hide();
    $(f + 'fieldset.property').show();

    $(f + 'p.area').removeClass('hidden');
    $(f + 'fieldset.other').show();

    $(f + 'p.parish').show();
    $(f + 'p.zone').show();

    switch (li) {
      case 0:
        $(f + 'p.area').hide();
        $(f + 'p.typology').show();
        $(f + 'p.price').show();
        break;
      default:
        $(f + 'p.typology').hide();
        $(f + 'p.price').show();
        $(f + 'p.area').show();
        break;
    }

    if (e != null) { document.getElementById(btn.attr('id')).onclick = e; btn.removeClass('disabled'); };

    if (bt) {
      ddl_Types(f, li, pl, true);
      ddl_Districts(f, true, false, false, true);
    }
  } else {
    $(f + 'fieldset.development').removeClass('hidden');

    $(f + 'fieldset.property').hide();
    $(f + 'fieldset.development').show();

    $(f + 'p.parish').hide();
    $(f + 'p.zone').hide();

    $(f + 'fieldset.other').hide();
    $(f + 'input[name$="qspGroup"]').attr('value', '-1');

    document.getElementById(btn.attr('id')).onclick = function() { return false; };
    btn.addClass('disabled');

    if (bt) {
      ddl_Districts(f, false, false, true, true);
      ddl_Clear($(f + 'p.district select'));
    }
  }
}

function search_Range(f, cl, cr, btn, gr, rn, c)
{ 
  var min = parseInt($(f + 'input[name$="' + cl + '"]').val().replace(/\./g, ''));
  var max = parseInt($(f + 'input[name$="' + cr + '"]').val().replace(/\./g, ''));

  if (min > 0 && max > 0) {
    if (min > max) {
      tooltip_OnLoad(document.getElementById(btn.attr('id')), global_GetResource(gr, rn, c));
      return false;
    }
  }

  return true;
}

function search_Validate(f)
{
  var bln = true;
  var v;

  $(f).each(function() {
    $(':input:visible', $(this)).each(function() {
      v = '';
      
      switch (this.type) {
        case 'text':
          v = this.value;
          break;
        
        case 'select-multiple':
          if ($(this).val() != null) v = $(this).val().join(',');
          break;

        case 'select-one':
          if (this.selectedIndex > 0) v = this.value;
          break;
      }

      if (v.length > 0) {
        bln = false;
        return false;
      }
    });
  });

  return bln;
}

$(function()
{
  var f = 'div.search ';

  var e = document.getElementById($(f + 'input[class*="btnMoreDetailed"]').attr('id'));
  if (e != null) e = e.onclick;
  
  $(f + 'input[name$="btnSearch"]').click(function()
  {
    if (search_Validate('div.search')) {
      var n = $(f + 'fieldset.development').is(':visible')
              ? 'VSD_REQUIRED'
              : 'VSP_REQUIRED'
      
      tooltip_OnLoad(document.getElementById($(this).attr('id')), global_GetResource('Simple', n));
      return false;
    }

    if (!search_Range(f, 'txtPriceMin', 'txtPriceMax', $(this), 'Simple', 'PRICE')) return false;

    if (!search_Range(f, 'txtAreaMin', 'txtAreaMax', $(this), 'Simple', 'AREA')) return false;
    
    return true;
  });

  $(f + '#group li').click(function()
  {
    if ($(this).attr('class').indexOf(' ') != -1)
      return false;

    $(f + '#group li').removeClass('active');
    $(this).addClass('active');

    $(f + '.form').reset();
    ddl_Clear(f + 'p.county select');
    ddl_Clear(f + 'p.parish select');
    ddl_Clear(f + 'p.zone select');

    var li = $(f + '#group li').index($(this));

    $(f + 'p.parish').show();
    $(f + 'p.zone').show();

    simple_OnLoad(li, true, $(f + 'input[name$="ucpLanguage"]').attr('value'), e);
  });

  $(f + 'select[name$="ddlTypologyMin"]').change(function()
  {
    ddl_TypologyMin(f, $(this));
  });

  $(f + 'select[name$="ddlTypologyMax"]').change(function()
  {
    ddl_TypologyMax(f, $(this));
  });

  $(f + 'p.name select').change(function()
  {
    ddl_Clear(f + 'p.county select');
    $(f + 'p.district select').val('0');
  });

  $(f + 'p.district select').change(function()
  {
    if ($(f + 'fieldset.development').is(':visible')) {
      $(f + 'p.name select').val('0');
      ddl_Counties(f, false, false, true, true);
    } else {
      ddl_Counties(f, true, false, false, true);      
    }
  });

  $(f + 'p.county select').change(function()
  {
    ddl_Parishes(f, true, false, false, true);
  });

  $(f + 'p.parish select').change(function()
  {
    ddl_Zones(f, true, false, false, true);
  });
});


/*
   =============================================
   Group:       Search
   UserControl: Advanced.ascx
   Pane:        Content
*/
function advanced_OnInit(pl)
{
  var f = '#as ';

  $(function() {
    $(f + 'p.type select[name$="ddlGroup"]').change(function()
    {
      var v = ($(this)[0].selectedIndex == 0) ? -1 : $(this).attr('value');

      ddl_Types(f, v, pl, true);
      $(f + 'p.furnished span').addClass('hidden');

      var pnl = $(f + 'fieldset.features');

      switch (parseInt($(this).attr('value'))) {
        case 0:
          $(f + 'p.typology select').removeAttr("disabled");
          break;
        
        case 222:
          $(f + 'p.typology select').removeAttr("disabled");
          pnl.removeClass('hidden');
          break;

        default:
          ddl_Disable($(f + 'p.typology select'));
          pnl.addClass('hidden');
      }
    });

    $(f + 'p.type select[name$="ddlType"]').change(function()
    {
      var chk = $(f + 'p.furnished span');
      
      switch (parseInt($(this).attr('value'))) {
        case 1:
          chk.removeClass('hidden');
          break;
        default:
          chk.addClass('hidden');
      }
    });

    $(f + 'select[name$="ddlTypologyMin"]').change(function()
    {
      ddl_TypologyMin(f, $(this));
    });

    $(f + 'select[name$="ddlTypologyMax"]').change(function()
    {
      ddl_TypologyMax(f, $(this));
    });

    $(f + 'p.district select').change(function()
    {
      ddl_Counties(f, true, false, false, true);
    });

    $(f + 'p.county select').change(function()
    {
      ddl_Parishes(f, true, false, false, false);
    });

    $(f + 'p.parish select').change(function()
    {
      ddl_Zones(f, true, false, false, false);
    });

    $(f + 'input[name$="btnSearch"]').click(function()
    {
      if ($(f + 'p.filters :checkbox:checked').length != 0) return true;
      
      if (search_Validate(f + 'div.form fieldset:lt(2)')) {
        tooltip_OnLoad(document.getElementById($(this).attr('id')), global_GetResource('Simple', 'VSP_REQUIRED'));
        return false;
      }
      
      if (!search_Range(f, 'txtPriceMin', 'txtPriceMax', $(this), 'Simple', 'PRICE')) return false;

      if (!search_Range(f, 'txtAreaMin', 'txtAreaMax', $(this), 'Simple', 'AREA')) return false;
      
      return true;
    });

    $(f + 'p.filters :checkbox').click(function() {
      chk_Exclusive($(this));
    });
  });
}


/*
   =============================================
   Group:       Properties
   UserControl: List.ascx
   Pane:        Content
*/
var cn_COMPARE = 'COMPARE';
var cn_SEARCH = 'SEARCH';
var cn_PROPERTY = 'PROPERTY';

$(function()
{
  $('#pl .actions :checkbox').click(function()
  {
    var chk = document.getElementById($(this).attr('id'));

    if ($.cookies.test()) {
      var c = cookies_Get(cn_COMPARE);
      var max = $('input[name$="qspComparator"]').val();

      var id = parseInt($(this).parent().parent().find('input[name$="qspProperty"]').attr('value'));

      if ($(this).attr('checked')) {
        if (c.length < max) {
          c.push(id);
          $.cookies.set(cn_COMPARE, c.join(';'));
        } else {
          $(this).attr('checked', false);
          tooltip_OnLoad(chk, global_GetResource('List', 'LIMIT'));
        }
      } else {
        cookies_Delete(cn_COMPARE, c, id, 0);
      }
    } else {
      $(this).attr('checked', false);
      tooltip_OnLoad(chk, global_GetResource('List', 'COOKIES'));
    }
  });

  $('#pl li.compare a').click(function()
  {
    if ($(this).attr('href') != null) {
      var c = cookies_Get(cn_COMPARE);

      $(this).addClass('enabled');

      if (c.length == 0) {
        var a = document.getElementById($(this).attr('id'));
        tooltip_OnLoad(a, global_GetResource('List', 'SELECT'));
      } else {
        window.location = $(this).attr('href') + '?id=' + c.join(',');
      }
    }

    return false;
  });

  $('#pl li.favorites a').click(function()
  {
    cookies_Set($(this), 'qspSearch', cn_SEARCH, 'ADD_SEARCH', 'REMOVE_SEARCH');

    return false;
  });

  $('#pl .actions input[name$="btnSelection"]').click(function()
  {
    cookies_Set($(this), 'qspProperty', cn_PROPERTY, 'ADD_PROPERTY', 'REMOVE_PROPERTY');

    return false;
  });
});


/*
   =============================================
   Group:       News
   UserControl: List.ascx
   Pane:        Left, Bottom
*/
function news_Marquee()
{
  $('.marquee ul').liScroll();
}

function news_Scroll(v, c)
{
  $('div.news .datalist').jCarouselLite({
    vertical: v,
    hoverPause: true,
    visible: 3,
    auto: 4000,
    speed: 2000
  });
}


/*
   =============================================
   Group:       Properties
   UserControl: Slideshow.ascx
   Pane:        Content, Left
*/
function slideshow_OnInit(ui, r, c, t)
{
  $(ui).slideshow_OnLoad({
    rows: r,
    columns: c,
    timeout: t
  });
}

(function($)
{
  $.fn.slideshow_OnLoad = function(param)
  {
    var _default = {
      rows: 1,
      columns: 3,
      timeout: 2000
    };

    var param = $.extend(_default, param);
    var id = '#' + $(this).attr('id');

    return this.each(function() {
      var timer;
      var i = 0;

      var r = 0;
      var c = 0;

      $('.item', $(this)).each(function() {
        $(this).addClass('dlpg' + r);

        c++;
        if (c == param.columns) {
          $(this).after('<div class="clear dlpg' + r + '">');
          c = 0;
        }

        i++;
        if (i == param.columns * param.rows) {
          r++;
          i = 0;
        }
      });

      for (var j = 0; j < r + 1; j++) {
        $('.dlpg' + j).wrapAll('<div class="paged">');
      }

      var css = '';
      $('.paged div[class*="dlpg"]').each(function() {
        css = $(this).attr('class');
        $(this).attr('class', css.substring(0, css.indexOf(' ')))
      });

      $(id + ' .paged').hide();
      $(id + ' .paged:first').show();

      var count = $('.item', $(this)).length;
      var size = param.columns * param.rows;

      if (count > size) {
        timer = setInterval("slideshow_OnChange('" + id + "')", param.timeout);

        $('.item', $(this)).hover(
 		  function() {
 		    clearInterval(timer);
 		  },
 		  function() {
 		    timer = setInterval("slideshow_OnChange('" + id + "')", param.timeout);
 		  }
 		);
      }
    });
  };
})(jQuery);

function slideshow_OnChange(d)
{
  var $active = $(d + ' .paged:visible');
  if ($active.length == 0) $active = $(d + ' .paged:last');

  var $next = $active.next().length ? $active.next() : $(d + ' .paged:first');

  $active.fadeOut(2500);
  $next.fadeIn(2500);
};
















/*
   =============================================
   UserControl: Banners.ascx
   Pane:        Left, Right
*/
function banner_OnLoad(c, swf, w, h, p)
{ 
  $(c).flash({
    src: swf,
    width: w,
    height: h,
    bgcolor: '#fff',
    wmode: 'transparent',
    quality: 'high',
    flashvars: p
  });
}


/*
   =============================================
   Group:       Properties
   UserControl: Detail.ascx
   Pane:        Content
*/
var _i = 0;
var _p = false;
var _t;
var _li;
var _m;
var _l = false;

function gallery_OnInit(_m)
{
  if (!this._l) gallery_OnLoad();

  this._m = _m;

  this._li = $('div.gallery .datalist img');
  var c = this._li.size();

  if (c > 1) {
    this._p = true;

    $('div.slideshow .stop').removeClass('hidden');
    $('div.slideshow .play').addClass('hidden');

    gallery_OnStart();
  } else {
    gallery_OnStop();
  }
}

function gallery_OnLoad()
{
  $('div.gallery .datalist').jCarouselLite({
    vertical: true,
    visible: 3,
    start: 0,
    circular: false,
    btnPrev: '.gallery .prev',
    btnNext: '.gallery .next',
    speed: 2000
  });

  this._l  = true;
}

function gallery_OnStart()
{
  gallery_OnChange($('div.photos .photo img'), this._li.get(this._i));

  this._i++;
  if (this._i > this._li.size() - 1) this._i = 0;

  this._t = setTimeout('gallery_OnStart()', this._m);
}

function gallery_OnStop()
{
  if (this._p) {
    this._p = false;

    $('div.slideshow .stop').addClass('hidden');
    $('div.slideshow .play').removeClass('hidden');
     
    clearTimeout(this._t);
  }
}

$(function()
{
  $('#pd div.menu li').click(function()
  {
    if ($(this).attr('class').length != 0) return false;

    $('#pd div.menu li').removeClass('active');
    $(this).addClass('active');

    switch ($('#pd div.menu li').index(this)) {
      case 0:
        $('#pd div.photos').removeClass('hidden');
        $('#pd div.videos').addClass('hidden');
        break;
      
      case 1:
        $('#pd div.photos').addClass('hidden');
        $('#pd div.videos').removeClass('hidden');

        gallery_OnStop();
        break;
    }
  });
});
















function thumb_GetImageUrl(t)
{
  return t.toString().replaceAt(t.lastIndexOf('/') + 1, '');
}

function gallery_OnChange(i, t)
{
  with (i) {
    attr('src', thumb_GetImageUrl(t.src));
    attr('title', t.title);
  }
}

$(function()
{
  $('#pd .gallery .datalist img').click(function()
  {
    gallery_OnStop();
    gallery_OnChange($('#pd .photo img'), $(this).get(0));
  });

  $('#pd .actions input[name$="btnSelection"]').click(function()
  {
    cookies_Set($(this), 'qspProperty', cn_PROPERTY, 'ADD_PROPERTY', 'REMOVE_PROPERTY');

    return false;
  });
});


/*
   =============================================
   Group:       Properties
   UserControl: Map.ascx
   Pane:        Content
*/

function gmap_OnInit(w, h, lat, lng, z, t)
{
  if (GBrowserIsCompatible()) {
    var icon = new GIcon();

    with (icon) {
      iconSize = new GSize(32, 32);
      shadow = '';
      shadowSize = new GSize(41, 34);
      icon.iconAnchor = new GPoint(16, 16);
      infoWindowAnchor = new GPoint(16, 16);
      infoShadowAnchor = new GPoint(10, 16);
    }

    function gmap_GetMarker(p) {
      var l = new GIcon(icon);
      l.image = '/app_themes/own/iframe/images/marker.png';

      return new GMarker(p, { icon: l });
    }

    var c = document.getElementById('map');
    with (c) {
      style.width = w + 'px';
      style.height = h + 'px';
    }

    var map = new GMap2(c);

    with (map) {
      setUIToDefault();
      disableScrollWheelZoom();

      var geo = new GLatLng(lat, lng);

      setCenter(geo, z);
      setMapType(t);

      addOverlay(gmap_GetMarker(geo));
    }
  }
}


/*
   =============================================
   Group:       Properties
   UserControl: MySpaceLaforet.ascx
   Pane:        Content
*/
$(function()
{
  $('#my .pf input[name$="btnSelection"]').click(function()
  {
    if (!$.cookies.test()) return false;

    var e = $(this).parent().find('input[name$="qspProperty"]').attr('value');

    cookies_Remove(e, cn_PROPERTY);
    document.location = window.location.pathname;

    return false;
  });

  $('#my .sf input[name$="btnSelection"]').click(function()
  {
    if (!$.cookies.test()) return false;

    var e = $(this).parent().find('input[name$="qspSearch"]').attr('value');

    cookies_Remove(e, cn_SEARCH);
    document.location = window.location.pathname;
  
    return false;
  });
});


/*
   =============================================
   Group:       Forms
   UserControl: ByEmail.ascx
   Pane:        Content
*/
$(function()
{
  $('#cr p.subject :checkbox').click(function() {
    chk_Exclusive($(this));
  });
});
























































































var _g;

function _gallery_OnInit(_m, _g)
{
  if (!this._l) { _gallery_OnLoad(_g, false); _gallery_OnLoad('div.floormodel', true); }

  this._m = _m;
  this._g = _g;

  this._li = $('#dd ' + _g + ' div.gallery .datalist img');

  var c = this._li.size();
  
  if (c > 1) {
    this._p = true;

    _gallery_OnStart();
  } else {
    _gallery_OnStop();
  }
}

function _gallery_OnStart()
{
  gallery_OnChange($(this._g + ' .photo img'), this._li.get(this._i));
  
  this._i++;
  if (this._i > this._li.size() - 1) this._i = 0;

  this._t = setTimeout('_gallery_OnStart()', this._m);
}

function _gallery_OnStop()
{
  if (this._p) {
    this._p = false;
    clearTimeout(this._t);
  }
}

function _gallery_OnLoad(_g, _h)
{
  $(_g + ' div.gallery .datalist').jCarouselLite({
    vertical: true,
    visible: 3,
    start: 0,
    circular: false,
    btnPrev: _g + ' .gallery .prev',
    btnNext: _g + ' .gallery .next',
    speed: 2000
  });

  this._l = true;

  if (_h) $('#dd ' + _g).addClass('hidden');
}

$(function()
{
  $('#dd div.menu li').click(function() {
    if ($(this).attr('class').length != 0) return false;
    
    gallery_OnStop();
    
    $('#dd div.menu li').removeClass('active');
    $(this).addClass('active');

    switch ($(this).attr('id').substring($(this).attr('id').lastIndexOf('_') + 1)) {
      case 'liPhotos':
        _g = 'div.photos';

        $('#dd div.floormodel').addClass('hidden');
        $('#dd div.videos').addClass('hidden');

        $('#dd ' + _g).removeClass('hidden');
        break;

      case 'liFloorModel':
        _g = 'div.floormodel';

        $('#dd div.photos').addClass('hidden');
        $('#dd div.videos').addClass('hidden');
        
        $('#dd ' + _g).removeClass('hidden');
        break;

      case 'liVideos':
        $('#dd div.photos').addClass('hidden');
        $('#dd div.floormodel').addClass('hidden');
        
        $('#dd div.videos').removeClass('hidden');
        return false;
    }

    _li = $('#dd ' + _g + ' div.gallery .datalist img');

    var _s = $('#dd ' + _g + ' .photo img').attr('src');
    _s = _s.insertAt(_s.lastIndexOf('/'), '/i')

    _i = _li.index($('#dd ' + _g + ' div.gallery .datalist img[src="' + _s + '"]'));

    _p = true;
    _gallery_OnStart();
  });
});

$(function()
{
  $('#dd div.photos .gallery .datalist img').click(function() {
    gallery_OnStop();
    gallery_OnChange($('#dd div.photos .photo img'), $(this).get(0));
  });
});

$(function()
{
  $('#dd div.floormodel .gallery .datalist img').click(function() {
    gallery_OnStop();
    gallery_OnChange($('#dd div.floormodel .photo img'), $(this).get(0));
  });
});
