$(function(){
    
    var hidNavIndex=$("#hidNavIndex");
    if(hidNavIndex.size()==1)
    {
        var _index=hidNavIndex.val();
        $("#AxNav").children().eq(_index).addClass("active");
    }
    
    
    // slider show
    SlideGallery(3,3,"property_mainPhotos",3,13);
    
    // popup e.keyCode == 13
    
    $(".div13").each(function(){
            
        var _div13=$(this);
        _div13.find("input").keydown(function(e){
            
            if(e.keyCode==13)
            {
                _div13.find('.btn13').click();
            }
            
        })
    });
    
    // height
    
//    var screenHeight = $(window).height();
//    var footerHeight = $('#footer').outerHeight();
//    var headerHeight = $('#header').outerHeight();
//    var contentHeight = $('#content').outerHeight();
//    var extraHeight = screenHeight - (headerHeight + contentHeight) - 18;
//    
//    if(extraHeight > footerHeight)
//    {               
//       $('#footer').height(extraHeight);
//    }
    
    
})


function SignNewsltter()
{
    var txtNewsletter=$("#txtNewsletter");
    if(txtNewsletter.val()=='' || txtNewsletter.val()=='Enter E-mail')
    {
        alert("Please enter your email.");
        txtNewsletter.focus();
    }
    else if(!isEmail(txtNewsletter.val()))
    {
        alert("Email is invalid.");
        txtNewsletter.focus();
    }
    else
    {
        $.post('AJAX/Newsletter.ashx?t='+new Date().getTime(),{'Email':txtNewsletter.val()},function(data){
            if(data>0)
            {
                alert("Thanks for your join.")
                txtNewsletter.val("Enter E-mail");                
            }
            else
            {
                alert("Email has existed. Please try another one.");
                txtNewsletter.focus();
            }
        })
    }
}



function Pro_MyList(action,propertyId)
{
    $.post('AJAX/MyProperties.ashx?t='+new Date().getTime(),{'action':action, 'propertyId':propertyId},function(data){
        if(data>0)
        {
            if(action=='remove')
            {
                var addtolist=$("div.addtolist[propertyId="+propertyId+"]");
                if(addtolist.size()>0)
                {
                    addtolist.find("div").eq(0).attr("class","checkboxArea");
                    addtolist.find("input").get(0).checked=false;
                }
            }
            GetMyProperties();
        }
    })
}

function GetMyProperties()
{
    $.post('AJAX/GetMyProperties.aspx?t='+new Date().getTime(),{},function(strHtml){
        var myproperties=$(".myproperties");
        if(myproperties.size()>0)
        {
            myproperties.html(strHtml);
        }
    });
}

//get properties detail page

function Pro_MyList_DetailPage(action,propertyId)
{
    $.post('AJAX/MyProperties.ashx?t='+new Date().getTime(),{'action':action, 'propertyId':propertyId},function(data){
        if(data>0)
        {
            if(action=='remove')
            {
                var addtolist=$("div.addtolist[propertyId="+propertyId+"]");
                if(addtolist.size()>0)
                {
                    addtolist.find("div").eq(0).attr("class","checkboxArea");
                    addtolist.find("input").get(0).checked=false;
                }
            }
            GetMyProperties_DetailPage();
        }
    })
}

function GetMyProperties_DetailPage()
{
    $.post('AJAX/GetMyProperties_DetailPage.aspx?t='+new Date().getTime(),{},function(strHtml){
        var myproperties=$(".myproperties_detailpage");
        if(myproperties.size()>0)
        {
            myproperties.html(strHtml);
        }
    });
}





function SlideGallery(_screen,_scroll,id,b7,l7)
{
    
    var _gal=$("#"+id);
    if(_gal.size()>0)
    {
        var _sum=_gal.find(".thumbs a").size();
        
        if(_sum>0)
        {
            var _big_a=_gal.find("div.photo").children();
            
            var _prev=_gal.find("a.prev").eq(0);
            var _next=_gal.find("a.next").eq(0);
            
            var _photos=_gal.find(".thumbs a img");
            
            //_big_photo.attr("src",_photos.eq(0).attr("src")).css({"width":"313px","height":"207px"});
            
            _gal.find(".thumbs a").each(function(i,el){
                
                var _a=$(this);
                
                _a.click(function(){
                    _gal.find("div.photo").fadeOut(function(){
                        _big_a.hide();
                        if(_big_a.find("a.close").size()>0)
                        {
                            _big_a.find("a.close").parent().show();
                        }
                        _big_a.eq(i).show();                        
                        $(this).fadeIn();
                    });
                })
                
            })

            
            if(_sum<=_screen)
            {
                _prev.hide();
                _next.hide();
                if(_sum==1)
                {
                    //_gal.find(".slider").hide().end().css("height","230px");
                }
            }
            else
            {   
                var i=0;
                var _itemWidth=_gal.find(".thumbs a").eq(0).width()+b7;
                
                if ($.browser.msie && $.browser.version <= 7) 
                {
                    _itemWidth=_gal.find(".thumbs a").eq(0).width()+l7;
                }
                
                var _width=_itemWidth*(_sum-_screen);
                var _box=$("#galleryBox");
                
                _next.click(function(){
                    i+=_scroll;
                    _x=_itemWidth*i;
                    if(i>_sum-_screen)
                    {
                        i=_sum-_screen;
                        _x=_width;
                    }
                    _box.animate({'marginLeft':-_x+'.px'},'1000',function(){ });
                });
            
                _prev.click(function(){
                    i-=_scroll;
                    _x=_itemWidth*i;
                    if(i<0)
                    {
                        i=0;
                        _x=0;
                    }
                    _box.animate({'marginLeft':-_x+'.px'},'1000',function(){ });
                });
                
            }
        }
        else
        {
            _gal.remove();
        }
    }
}




