/* error suppression

function silentErrorHandler() {return true;}
window.onerror=silentErrorHandler;
 */
var helvetica = { src: '/Common/Flash/helvetica.swf', wmode: 'opaque' };
sIFR.activate(helvetica);

function headFlash(){
    sIFR.replace(helvetica, {
      selector: 'h2',
      css: '.sIFR-root { background-color: #ffffff; color: #666666; }',
      wmode: 'transparent'
    });
    sIFR.replace(helvetica, {
      selector: 'h3',
      css: [
        '.sIFR-root { background-color: #ffffff; color: #666666; }',
        'a { color: #F7941D; text-decoration: underline; }',
        'a:link { color: #F7941D; }',
        'a:hover { color: #000000; text-decoration: underline; }'
      ],
      wmode: 'transparent'
    });
    sIFR.replace(helvetica, {
      selector: 'p#do-strapline',
      css: '.sIFR-root { background-color: #ffffff; color: #f58224; }',
      wmode: 'transparent'
    });
    sIFR.replace(helvetica, {
      selector: 'div.propertyContactDetails h4',
      css: '.sIFR-root { background-color: #ffffff; color: #666666; font-weight: bold }'
    });
}

var QueryString = {};
var param = document.location.search.substring(1).split("&");
for (var i=0; i<param.length; i++){
    var pair = param[i].split("=");
    if (pair[0].length > 0)
        QueryString[pair[0]] = (pair.length > 1)?pair[1]:"";
} 

var pageurl = (location.pathname.lastIndexOf('/')===location.pathname.length-1) ? location.pathname.toLowerCase()+'default.aspx' : location.pathname.toLowerCase();
var sectionurl = location.pathname.substring(0,location.pathname.lastIndexOf('/')+1).toLowerCase()+'default.aspx';
if (QueryString.fund) sectionurl = "/fundsmanagement/"+QueryString.fund+"/default.aspx";

function locmatch(c,l){
    $(c).each(function(){
        if($('a:eq(0)', this).attr('href')){
            var nlink = ($('a:eq(0)', this).attr('href').lastIndexOf('/')===$('a:eq(0)', this).attr('href').length-1) ? $('a:eq(0)', this).attr('href').toLowerCase()+'default.aspx' : $('a:eq(0)', this).attr('href').toLowerCase();
        }
        if(l===nlink){
            $(this).addClass('selected');
        }
    });
    return;
}

function navInit(){
    if($('.sideNav li').length>0){
        locmatch('#navSecondary li',sectionurl);
        locmatch('.sideNav li',pageurl);
    } else {
        locmatch('#navSecondary li',pageurl);
    }
    $('#navSecondary li, .sideNav li').not('.selected').each(function(){
        $('img', this).each(function(){
            var s = $(this).attr('src').split('?');
            $(this).data('off',s[0]);
            $(this).data('on',s[1]);
        }).hover(function(){
            $(this).attr('src', $(this).data('on'));
        },function(){
            $(this).attr('src', $(this).data('off'));
        });
    });
    $('#navSecondary li.selected, .sideNav li.selected').each(function(){
        $('img', this).attr('src', $('img', this).attr('src').split('?')[1]).unbind();
    });
    var ro = $('#navSecondary li.selected').parent().parent();
    if (ro.hasClass('closed')){
        $(ro).toggleClass('closed');
    }
}

$(window).load(function() {
    $(".sIFR-replaced").height("auto");
});

$(document).ready(function() {

    headFlash();
    navInit();

    $('img.rollover, input.rollover').rollover();

    $('#back').click(function() {
        window.history.back();
    });

    if ($('.slideShow li').length == 0) $('.gallery, .gallery2').hide();

    $('.slideShowControl #btnSlideBack').click(function() {
        var i = $('.slideShow li').index($('.slideShow li:visible')[0]);
        var h = (i - 1 == -1) ? $('.slideShow li').size() - 1 : i - 1;
        $('.slideShow li:eq(' + i + ')').hide();
        $('.slideShow li:eq(' + h + ')').show();
    });

    $('.slideShowControl #btnSlideNext').click(function() {
        var i = $('.slideShow li').index($('.slideShow li:visible')[0]);
        var j = (i + 1 == $('.slideShow li').size()) ? 0 : i + 1;
        $('.slideShow li:eq(' + i + ')').hide();
        $('.slideShow li:eq(' + j + ')').show();
    });

    $('.functions .navigation img').rollover();
    $('.functions .navigation > li').hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });

    $('#navSecondary a:has(em)').click(function() {
        var i = $('#navSecondary li').index($(this).parent()[0]);
        $('#navSecondary li').not(':eq(' + i + ')').addClass('closed');
        $(this).parent().toggleClass('closed');
    });

    $('.gallery').each(function() {
        $('ul', this).addClass('hide');
        if ($('ul.slideShow li', this).length > 0) {
            $(this).append('<div id="gallery"></div>');
            
            var swfins = new SWFObject('/Common/Flash/page_flip-prev_next.swf', 'swfGallery', '300', '340', '8', '#ffffff');
            //swfins.addParam('allowscriptaccess','always');
            swfins.addParam('wmode', 'opaque');
            $('ul.slideShow li').each(function(j) {
                swfins.addVariable('u' + (j + 1), $('img', this).attr('src'));
            });
            if (!swfins.write('gallery')) {
                $('ul', this).removeClass('hide');
                $('ul:eq(0) li', this).not(':eq(0)').hide();
            };
        } else {
            $(this).hide();
        }
    });

    $('.gallery2').each(function() {
        $('ul', this).addClass('hide');
        if ($('ul.slideShow li', this).length > 0) {
            $(this).append('<div id="gallery"></div>');
            var swfins = new SWFObject('/Common/Flash/page_flip_linked.swf', 'swfGallery', '300', '340', '8', '#ffffff');
            //swfins.addParam('allowscriptaccess','always');
            swfins.addParam('wmode', 'opaque');
            $('ul.slideShow li').each(function(j) {
                swfins.addVariable('u' + (j + 1), $('img', this).attr('src'));
            });
            if (!swfins.write('gallery')) {
                $('ul', this).removeClass('hide');
                $('ul:eq(0) li', this).not(':eq(0)').hide();
            };
        } else {
            $(this).hide();
        }
    });

    $('#btnEnlarge').click(function() {
        var i = $('.slideShow li').index($('.slideShow li:visible')[0]);
        lightbox(i, 'nf');
    });

    /* bio list */
    $('dl.listBio').each(function() {
        var lochash = location.hash || false;
        if (lochash) {
            var lochash = (lochash.indexOf('?') > -1) ? lochash.substring(lochash.indexOf('#') + 1, lochash.indexOf('?')) : lochash.substring(lochash.indexOf('#') + 1);
            if ($('dl.listBio dt[id*=' + lochash + ']').length > 0) {
                $('#' + lochash).removeClass('closed').next().removeClass('closed');
            }
        }
    });
    $('dl.listBio dt a').click(function() {
        var i = $('dl.listBio dt').index($(this).parent()[0]);
        var c = $('dl.listBio dt').index($('dl.listBio dt').not('.closed')[0]);
        $('dl.listBio dt, dl.listBio dd').addClass('closed');
        if (i !== c) {
            $('dl.listBio dt:eq(' + i + '), dl.listBio dd:eq(' + i + ')').removeClass('closed');
        }
    });

    /* bio accordian */
    $('ul.listBio').each(function() {
        $('div', this).hide();
        var list = $(this);
        $('> li > a', this).click(function() {
            if ($(this).next().is(':visible')) {
                $(this).removeClass('expand');
                $(this).next().hide('fast');
            } else {
                $('div', list).hide('fast');
                $(this).parent().parent().find('> li a').removeClass('expand');
                $(this).addClass('expand');
                $(this).next().slideDown();
            }
        });
    });


    $('.listBio li:eq(0) > a').addClass('expand');
    $('.listBio div:eq(0)').show();

    $('#searchLeaseCategory .clear').click(function() {
        $('#searchLeaseCategory select').each(function() {
            this.selectedIndex = 0;
        });
        return false;
    });

    $('.propertyDetailsTable .clicktoexpand').click(function() {
    $('.availableLease').toggle();
    });

});

$(window).resize(function(){
    $('#bannerflash').width($('#content').width()+'px');
});


function lightbox(i,t) {
    if (t == 'nf')
        var ele = $('.gallery a').get(i);
    else
        var ele = $('.gallery a').get(i - 1);
    var url = $(ele).attr('href');
    var caption = $(ele).attr('title') || $(ele).attr('name') || '';
    var imageGroup = $(ele).attr('rel') || '';
    //  var caption = $('.gallery a').eq(i).attr('title') || $('.gallery a').eq(i).attr('name')|| '';
    //  var imageGroup = $('.gallery a').eq(i).attr('rel') || '';
    
    tb_show(caption, url, imageGroup);
}

function lightbox2(i, t) {
    if (t == 'nf')
        var ele = $('.gallery2 .lrgImg').get(i);
    else
        var ele = $('.gallery2 .lrgImg').get(i - 1);
    var url = $(ele).attr('href');
    var caption = $(ele).attr('title') || $(ele).attr('name') || '';
    var imageGroup = $(ele).attr('rel') || '';
    //  var caption = $('.gallery a').eq(i).attr('title') || $('.gallery a').eq(i).attr('name')|| '';
    //  var imageGroup = $('.gallery a').eq(i).attr('rel') || '';

    tb_show(caption, url, imageGroup);
}

function slideshowClick(i) {
    var ele = $('.gallery2 .outLink').get(i-1);
    var url = $(ele).attr('href');
    if (ele != 'javascript:void(0);') {
        window.location.href = url;
        // var win = url == "/MortgageMinder/" ? window.location.href = url : window.open(url);
    }
}

function swfimgHeight(h){
    if(h==='600'){
        $('#internal').hide();
        $('#main').height('392px');
        $('#banner, #bannerflash').height(h+'px');
    } else {
        $('#banner, #bannerflash').height(h+'px');
        $('#main').height('auto');
        $('#internal').show();
    }
}

//print image
function PrintImg(imgSrc) {

   window.open('/Print.aspx?Id='+imgSrc, '', 'width=100,height=100,left=0,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=no,toolbar=no,top=0');
    return false;
}