﻿var isIE6 = $.browser.msie && $.browser.version == 6.0;

$(document).ready(function(){
    TenureChange();
    $("#tenure").change(TenureChange);
    $('body').prepend('<div id="galhldr" style="display: none;"></div><div id="cloak" style="display: none;" />');
    $("span.print").html('<a href="#" onclick="window.print();return false">PRINT</a>');
});

function TenureChange(){
    el = (this.id == 'tenure') ? this : document.getElementById('tenure');
    if (!el) return false;
    var txt = el.options[el.selectedIndex].text;
    if (txt.indexOf('Shared') >= 0) {
        $(".pricefld:not(#pricefld2)").hide();
        $("#pricefld2").show();
    } else {
        if (txt.indexOf('Rent') >= 0) {
            $(".pricefld:not(#pricefld3)").hide();
            $("#pricefld3").show();
        } else {
            $(".pricefld:not(#pricefld1)").hide();
            $("#pricefld1").show();
        }
    }
}

function LoadScroller(){
	location.hash = "gal";
    $("#next, #prev").css("display","block");
    $("#imagelist").jCarouselLite({
        btnNext: "#next",
        btnPrev: "#prev",
        visible: 4,
        speed: 500
    });
    $(".fadimg:first").show();
    $(".scrlimg").click(function(evt) {
        evt.preventDefault();
        $(".fadimg[src$="+$(this).attr("src").replace('http://'+location.host,'')+"]").stop(false,true).fadeIn("slow");
        $(".fadimg:not(.fadimg[src$="+$(this).attr("src").replace('http://'+location.host,'')+"])").stop(false,true).fadeOut("slow");
    });
    if (!isIE6)
        document.getElementById("imgnav").innerHTML = document.getElementById("imgnav").innerHTML.replace(/\.gif/gi,'.png');
    $("#imgnav").show().fadeTo(1,0.2);
    $("#closebtnhldr").click(HideGallery);
    $("#MainGalImg, #imgnav").mouseover(function(){
        $("#imgnav").stop().fadeTo("fast",0.8);
    })
    $("#MainGalImg, #imgnav").mouseout(function(){
	    $("#imgnav").stop().fadeTo("fast",0.2);
    })
}

function getGallery(url) {
    $("#cloak").css({
			backgroundColor : '#000',
			position : 'absolute',
			top : '0px',
			left : '0px',
			filter : 'alpha(opacity=60)', // IE =(
			opacity : '0.6', // Good Browser =D
			zIndex : '9998',
			width : !isIE6 ? '100%' : $(window).width() + 'px',
			height : $(document).height() + 'px'
		}).fadeIn('normal').click(HideGallery);
    $('#galhldr').css({
			backgroundColor : '#fff',
			position : 'absolute',
			top : '125px',
			left : ($(window).width()/2)-295,
			width: '592px',
			height: '570px',
			overflow: 'hidden',
			zIndex : '9999'
		}).show("slow").load(url,null,LoadScroller);
}

function HideGallery() {
    $("#cloak").fadeOut('fast');
    $('#galhldr').fadeOut('fast');
}

function PrevGalImg(){
   $('.fadimg').stop(true,true)
   el = ($('.fadimg:visible').prev().length > 0) ? $('.fadimg:visible').prev(): $(".fadimg:last");
   el.fadeIn('slow').siblings().fadeOut('slow');
}

function NextGalImg(){
    $('.fadimg').stop(true,true)
    el = ($('.fadimg:visible').next().length > 0) ? $('.fadimg:visible').next(): $(".fadimg:first");
    el.fadeIn('slow').siblings().fadeOut('slow');
}