﻿$(document).ready(function() 
{
    var vIsIE = jQuery.browser.msie;
    var vDescriptHeight;
    var vAmenOnSiteHeight;
    var vAmenNearbyHeight;
    var vRecOnSiteHeight;
    var vRecNearbyHeight;
    var vOnsiteHeight = 200;
    var vAddHeight = 10;
    var vIsMaxDescript = false;
    var vIsMaxAmenities = false;
    var vIsMaxRecreation = false;
    var vTempAddHeight = 6;
    if (vIsIE) vTempAddHeight =  0;
    var vUpImage = LinkPath("/images/up.png");
    var vDownImage = LinkPath("/images/down.png");
    var vDescMinHeight = '375px';
    
    $('html').addClass('js');    
    function AddDescriptMore()
    {
        $('div.descript-text').wrapInner('<div class="overview_desc_inner"></div>').each(function(index) 
        {
            var $container = $(this);
            var $inner = $container.find('div.overview_desc_inner');  
                    
            var vObj =  vObj = $("div.descript");
            var vHeight = GetHeight($inner);
            
            if (typeof(vDescriptHeight) == 'undefined')
                    vDescriptHeight = vHeight;
                else
                    vHeight = vDescriptHeight;
     
            if (vObj != null && $inner.height() + 10 > vObj.height())
            {  
                $("a.description-arrows").css('visibility','visible'); 
                             
                vObj.css('height',vDescMinHeight);   
                $container.css('height',vObj.height() + 'px');            
                vReadMore = '<div class="tag"><p>&hellip; <a href="#">more</a></p></div>';
                          
                $(vReadMore).appendTo($container).find('a').click(function() 
                {
                    vIsMaxDescript = true;
                    $("a.description-arrows").find('img')[0].src = vUpImage;
                    
                    if (vObj != null)
                    {
                        vObj.animate({height: vHeight + 33}, 'med');
                        $(this).parents('div.tag').remove();
                    }
                    return false;
                });
            } 
        });
    }
    
    function AddAmenitiesMore()
    {
        $('div.amen-onsite-items, div.amen-nearby-items').wrapInner('<div class="container-inner"></div>').each(function(index) 
        {
            var $container = $(this);
            var $classname = $container.attr('className');
            var $inner = $container.find('div.container-inner'); 
            var $height = GetHeight($container);
           
            if ($classname == 'amen-nearby-items')
            {
                if (typeof(vRecNearbyHeight) == 'undefined')
                    vAmenNearbyHeight = $height;
                else
                    $height = vAmenNearbyHeight;
            }
            
            var vIsContinue = false;
            if ($height > vOnsiteHeight && ($classname == 'amen-onsite-items'))
            {
                vIsContinue = true;
                $container.css('height', (vOnsiteHeight - vTempAddHeight) + 'px');
            } else 
            if ($height > 148 && $classname == 'amen-nearby-items')
            {
                var vRecColheight = parseInt($('div.amen-col').css('height'), 10);
                var vRecOnsiteItemsHeight = parseInt($('div.amen-onsite-items').attr('clientHeight'),10);
                var vTempHeight = vRecColheight - vRecOnsiteItemsHeight - 30;            
                if ($height > vTempHeight)
                {
                    vIsContinue = true;
                    $container.css('height',(vTempHeight - vTempAddHeight) + 'px');
                }
            } else {
                $container.css('height',$height + 'px');
            }
            
            if (vIsContinue && $container != null)
            {                
                var vHeight = $inner.height();        
                $('<div class="tag"><p>&hellip; <a href="#">more</a></p></div>').appendTo($container).find('a').click(function() 
                {
                    vIsMaxAmenities = true;
                    $("a.amenities-double-down-arrows").find('img')[0].src = vUpImage;
                    
                    if ($container != null)
                    {   
                        if ($classname == 'amen-onsite-items')
                        {
                            var vAmenColObj = $("div.amen-col");
                            var vTempHeight = parseInt(vAmenColObj.css('height'), 10) + vHeight - vOnsiteHeight + vAddHeight;                    
                            vAmenColObj.css('height', vTempHeight + 'px');                        
                                  
                            //$container.animate({height: vHeight + 3}, 'med'); // Safari Min error.
                            $container.css('height', vHeight + 'px');                    
                            $(this).parents('div.tag').remove();
                        } else 
                        if ($classname == 'amen-nearby-items')
                        {
                            var vAmenOnSiteItemsHeight = parseInt($('div.amen-onsite-items').css('height'),10);
                            
                            var vTempHeight = 30 + vAmenOnSiteItemsHeight + $height;
                            $("div.amen-col").css('height', vTempHeight + 'px');
                            
                            $container.css('height', vTempHeight + 'px');
                            //$container.animate({height: vTempHeight + 3}, 'med');                   
                            $(this).parents('div.tag').remove();
                        }
                    }
                    return false;
                });
            } 
        });
    }    
    
    function AddRecreationMore()
    {
        $('div.rec-onsite-items,div.rec-nearby-items').wrapInner('<div class="container-inner"></div>').each(function(index) 
        { 
            var $container = $(this);
            var $classname = $container.attr('className');
            var $inner = $container.find('div.container-inner'); 
            var $height = GetHeight($container);

            if ($classname == 'rec-nearby-items')
            {
                if (typeof(vRecNearbyHeight) == 'undefined')
                    vRecNearbyHeight = $height;
                else
                    $height = vRecNearbyHeight;
            }
            
            var vIsContinue = false;
            if ($height > vOnsiteHeight && ( $classname == 'rec-onsite-items'))
            {
                vIsContinue = true;
                $container.css('height', (vOnsiteHeight - vTempAddHeight) + 'px');
            } else 
            if ($height > 148 && $classname == 'rec-nearby-items')
            {
                var vRecColheight = parseInt($('div.rec-col').css('height'), 10);
                var vRecOnsiteItemsHeight = parseInt($('div.rec-onsite-items').attr('clientHeight'),10);
                var vTempHeight = vRecColheight - vRecOnsiteItemsHeight - 30;            
                if ($height > vTempHeight)
                { 
                    vIsContinue = true;
                    $container.css('height',(vTempHeight - vTempAddHeight) + 'px');
                }
            } else {
                $container.css('height',$height + 'px');
            }
            
            if (vIsContinue && $container != null)
            {                           
                var vHeight = $inner.height();       
                $('<div class="tag"><p>&hellip; <a href="#">more</a></p></div>').appendTo($container).find('a').click(function() 
                {
                    vIsMaxRecreation = true;
                    $("a.recreation-double-down-arrows").find('img')[0].src = vUpImage;
                                        
                    if ($container != null)
                    {
                        if ($classname == 'rec-onsite-items')
                        {
                            var vRecColObj = $("div.rec-col");
                            var vTempHeight = parseInt(vRecColObj.css('height'), 10) + vHeight - vOnsiteHeight + vAddHeight;  
                                              
                            vRecColObj.css('height', vTempHeight + 'px');                        
                                  
                            //$container.animate({height: vHeight + 3}, 'med');
                            $container.css('height', vHeight + 'px');                    
                            $(this).parents('div.tag').remove();
                        } else 
                        if ($classname == 'rec-nearby-items')
                        {
                            var vRecOnSiteItemsHeight = parseInt($('div.rec-onsite-items').css('height'),10);
                            
                            var vTempHeight = 30 + vRecOnSiteItemsHeight + $height;
                            $("div.rec-col").css('height', vTempHeight + 'px');
                            
                           // $container.animate({height: vTempHeight + 3}, 'med');
                           $container.css('height', vTempHeight + 'px');                    
                            $(this).parents('div.tag').remove();
                        }
                    }
                    return false;
                });
            } 
        });
    }
    
    function MaxAmenities ()
    {  
        $('div.amen-onsite-items').css('height', vAmenOnSiteHeight + 'px');
        $('div.amen-nearby-items').css('height',vAmenNearbyHeight + 'px');
        $("div.amen-col").css('height', (vAmenOnSiteHeight + vAmenNearbyHeight + 30) + 'px');   
        $("div.amen-col").find('div.tag').remove();
        vIsMaxAmenities = true;
        $("a.amenities-double-down-arrows").find('img')[0].src = vUpImage;
    }
    
    function MinAmenities ()
    {
        $('div.amen-onsite-items').css('height', vAmenOnSiteHeight + 'px');
        $('div.amen-nearby-items').css('height',vAmenNearbyHeight + 'px');
        $("div.amen-col").find('div.tag').remove();
        $("div.amen-col").css('height', '375px');         
        AddAmenitiesMore(); 
        vIsMaxAmenities = false; 
        $("a.amenities-double-down-arrows").find('img')[0].src = vDownImage;
    }
    
    function MaxRecreation ()
    {
        $('div.rec-onsite-items').css('height', vRecOnSiteHeight + 'px');
        $('div.rec-nearby-items').css('height',vRecNearbyHeight + 'px');
        $("div.rec-col").css('height', (vRecOnSiteHeight + vRecNearbyHeight + 30) + 'px');   
        $("div.rec-col").find('div.tag').remove();
        vIsMaxRecreation = true;
        $("a.recreation-double-down-arrows").find('img')[0].src = vUpImage;
    }
    
    function MinRecreation ()
    {
        $('div.rec-onsite-items').css('height', vRecOnSiteHeight + 'px');
        $('div.rec-nearby-items').css('height',vRecNearbyHeight + 'px');
        $("div.rec-col").find('div.tag').remove();
        $("div.rec-col").css('height', '375px');
        AddRecreationMore(); 
        vIsMaxRecreation = false; 
        $("a.recreation-double-down-arrows").find('img')[0].src = vDownImage;
    }
    
    $("a.amenities-double-down-arrows").click(function() 
    {
        if (vIsMaxAmenities == false)
            MaxAmenities ();
        else
            MinAmenities ();
    });
    
    $("a.recreation-double-down-arrows").click(function() 
    {
        if (vIsMaxRecreation == false)
            MaxRecreation();
        else
           MinRecreation();
    });

    function LoadReview()
    {
        var obj = $('#zd_aReviews');
        if (obj != null)
        {
            $('a.write-a-review').each(function(index) 
            { 
                var $container = $(this);
                if ($container != null)
                    $container[0].href= obj[0].href;
            });
        }
    }
    
    function LoadAmenites(vOnsite, vNearBy, vIsAmen )
    {
        var $OnsiteHeight = 0;
        var $NearbyHeight = 0;
        var $divOnsite = $(vOnsite);
        var $divNearby = $(vNearBy);
               
        if ($divOnsite != null)
            $OnsiteHeight = GetHeight($divOnsite);
        if ($divNearby != null)
            $NearbyHeight = GetHeight($divNearby);
        
        if (($OnsiteHeight + $NearbyHeight) > 350)
        {
            if (vIsAmen)
            {
                if (typeof(vAmenOnSiteHeight) == 'undefined')
                    vAmenOnSiteHeight = $OnsiteHeight;
                if (typeof(vAmenNearbyHeight) == 'undefined')
                    vAmenNearbyHeight =$NearbyHeight;
                AddAmenitiesMore();
                $("a.amenities-double-down-arrows").css('visibility','visible'); 
            }
            else
            {
                if (typeof(vRecOnSiteHeight) == 'undefined')
                    vRecOnSiteHeight = $OnsiteHeight;
                if (typeof(vRecNearbyHeight) == 'undefined')
                    vRecNearbyHeight =$NearbyHeight;
                AddRecreationMore();
                $("a.recreation-double-down-arrows").css('visibility','visible'); 
            }               
        }        
    }
    
    function GetHeight (vObj)
    {    
         var $Height = parseInt(vObj.attr('clientHeight'), 10);
         if ($Height <= 0) //IE6
            $Height =  parseInt( vObj.attr('offsetHeight'), 10);
         return $Height; 
    }
    
    function MaxDescription ()
    {
        $('div.descript').css('height', (vDescriptHeight+30) + 'px');
        $("div.descript").find('div.tag').remove();
        vIsMaxDescript = true;
        $("a.description-arrows").find('img')[0].src = vUpImage;
    }
    
    function MinDescription ()
    {
        $("div.descript").find('div.tag').remove();
        //$("div.descript").css('height', '368px');
        $("div.descript").css('height', vDescMinHeight);
        AddDescriptMore(); 
        vIsMaxDescript = false; 
        $("a.description-arrows").find('img')[0].src = vDownImage;
    }
    
    $("a.description-arrows").click(function() 
    {
        if (vIsMaxDescript == false)
            MaxDescription ();
        else
            MinDescription ();
    });
    
    AddDescriptMore();
         
    LoadAmenites("div.amen-onsite-items", "div.amen-nearby-items", true);
    LoadAmenites("div.rec-onsite-items", "div.rec-nearby-items", false);
    LoadReview();    
    LoadIFrameAD();
});	