/*

	Filename             sitewide.js
	Detail               Site functionality
	Author:              thunder::tech inc.
	License:             CLIENT is defined as the owner of online property from which this file resides or this code is referenced in.
						 ADDITIONAL PARTY is defined as anyone other than thunder::tech or CLIENT.
						 No right is granted to ADDITIONAL PARTY to sell, distribute, modify or otherwise transfer the following source code without explicit written permission by CLIENT or thunder::tech.

*/

/*  ================================
     Sitewide JavaScript
    ================================ */

var DDR = {};
var ua = {};

// Set up for browser environment
ua.Opera = navigator.userAgent.match(/Opera Mini/i);
ua.Android = navigator.userAgent.match(/Android/i);
ua.AndroidTablet = navigator.userAgent.match(/Android/i) && (!navigator.userAgent.match(/Mobile/i));
ua.BlackBerry = navigator.userAgent.match(/BlackBerry/i);
ua.iPhone = navigator.userAgent.match(/iPhone/i);
ua.iPad = navigator.userAgent.match(/iPad/i);
ua.iPod = navigator.userAgent.match(/iPod/i);

DDR.pageLoaded = function () {
    //thunder.client.DDR.flashReplace();
    //thunder.client.modify.rollImages();
    //thunder.client.modify.linkOptions();
    //thunder.client.modify.tabSet();
    //thunder.client.modify.treeMenu(false);
    //thunder.client.modify.treeMenu(false, [thunder.client.modes.separatorTreeMenu]);
    //thunder.client.modify.treeMenu(false, [thunder.client.modes.imageTreeMenu]);
    thunder.client.modify.selfLabelFields();
    //thunder.client.modify.requireFields();
    //thunder.client.modify.dropSelector(true);


    /*----set up shop 1-2012----*/
    DDR.setUpShopHangingSign = $('#set-up-shop-hanging-sign');
    DDR.setUpShopSignHanger = $('#set-up-shop-sign-hanger');
    DDR.transformCapable = !($.browser.msie && ($.browser.version <= 8));
    // alert(DDR.transformCapable);
    if (DDR.setUpShopHangingSign.length > 0) {

        if (DDR.transformCapable) {
            DDR.setUpShopSignHanger.css({ opacity: 0, display: 'block' }).animate({ opacity: 1 }, { duration: 2000, complete: DDR.onSignReady });
        }
        else {
            DDR.setUpShopSignHanger.css({ display: 'block' });
            DDR.setUpShopHangingSign.animate({ top: '106px' }, { duration: 1000 }).find('img').css({ left: '-75px' })[0].src = '/media/images/set-up-shop-sign-no-transform.png';
            setTimeout(DDR.onSignHanging, 800);
        }
    }
    /*----set up shop 1-2012----*/



    $(DDRSimpleSlideshow.onReady);
    $(DDRHomeSlideshow.onReady);
    /*====gallery scripts====*/
    if ($('#donations .thunder-scroll-viewport img').size() > 1) {
        thunder.client.modify.scrollFeature(400, 3000, 500);

        var count = 1;
        $('.slider > li').each(function () {
            //  $(this).append('<div class="count">' + count + '</div>');
            count += 1;
        });
        if (count > 8) {
            $('.slider').scrollIt({
                menuHeight: 85,
                menuWidth: 730,
                itemHeight: 75,
                itemWidth: 100,
                initialItem: 0
            });
        } else {
            $('.scrollIt-arrow').css('display', 'none');
        }


    }

    if ($('.display-thunder-scroll-viewport img').size() > 1) {
        var artwork = thunder.client.modify.scrollFeatureArt(380, 3000, 500, 'display-');

        $("#legend a.artprev").click(artwork.previous);
        $("#legend a.artnext").click(artwork.next);

    }

    $('.piclight-white').mouseenter(DDR.highlightPicRoll).mouseleave(DDR.highlightPicRoll);
    if ($('#gallery2-slideshow').length > 0) {
        $('#gallery2-slideshow').cycle({ activePagerClass: 'activeSlide', pager: '#counters', slideExpr: 'img' }); //http://jquery.malsup.com/cycle/options.html
        if ($('div.picbox p').length > 0) {
            $('div.picbox p').expander({ //http://plugins.learningjquery.com/expander/index.html#getting-started
                slicePoint: 150,  // default is 100
                expandText: ' more ', // default is 'read more...'
                //collapseTimer: 5000, // re-collapses after 5 seconds; default is 0, so no re-collapsing
                userCollapseText: ' less '  // default is '[collapse expanded text]'
            });
        };
    }


    //some IE hacks
    if ($.browser.msie) {
        $("#skypenumber").show();
        $("#phonenumber").hide();

        if (parseInt($.browser.version) == 7) {
            $("#benefitsphoto").css("position", "relative");
            $("#benefitsphoto").css("left", "-70px");

            $("#googleplus").css("float", "right");
            $("#googleplus").css("top", "-20px");
            $("#googleplus").css("left", "-65px");
        }
    }





    thunder.client.workarounds.alphaImages();
    thunder.client.workarounds.labelAsBrowser();
    if ($('#home-slideshow').length > 0) {
        $('#home-slideshow').cycle({ activePagerClass: 'activeSlide', pager: '#counters', slideExpr: 'img' }); //http://jquery.malsup.com/cycle/options.html
    }


    $('#advanced-search').click(DDR.advancedSearch);
    $('#hide-advanced-search').click(DDR.advancedSearch);
    DDR.locator = $('#locator');
    $('#quick-links').children('a').each(DDR.quickLinkHover);
    $('#locator-expander').click(DDR.expandLocator);

    DDR.expandLinks = $('.expand-links').children().click(DDR.expandLink);
    DDR.expandsubLinks = $('.expand-sublinks').children().click(DDR.expandsubLink);

    if ($("#pic_roll").length > 0) {
        //first album should be open and displayed
        $("#pic_roll ul li:nth-child(1)").click();
        //        alert($("#pic_roll ul li:nth-child(1) a").html());
    }
    if ($(".picbox").length > 0) {
        //first album should be open and displayed
        $("#pic_roll div:nth-child(1)").click();
        //        alert($("#pic_roll ul li:nth-child(1) a").html());
    }

    $('.highlight-white').mouseenter(DDR.highlightRectangle).mouseleave(DDR.highlightRectangle);
    //flash map placements
    if ($("#ddrSwfMapDivUSA").length > 0) { DDR.flashReplaceUSAMap(); }
    if ($("#ddrSwfMapDivBrazil").length > 0) { DDR.flashReplaceBrazilMap(); }
    if ($("#ddrValuTextVideo").length > 0) { DDR.flashReplaceValuText(); }
    DDR.autocomplete();
    DDR.applyCurrentMenu();
    // DDR.socialIconsHover();
    //DDR.sustainabilityFlash();
    DDR.searchformat();
    DDR.enableEnterKey(); //enable the hit enter key
    setInterval(DDR.radiusSearch, 200);
}

/*=============set up shop 1-2012=============*/
DDR.onSignReady = function () {
    setTimeout(DDR.onSignHanging, 800);
    DDR.setUpShopHangingSign.css({ transform: 'rotate(80deg)' }).animate({ transform: 'rotate(-40deg)', top: '106px' }, { duration: 1000 }).animate({ transform: 'rotate(20deg)' }, { duration: 1000 }).animate({ transform: 'rotate(-10deg)' }, { duration: 800 }).animate({ transform: 'rotate(5deg)' }, { duration: 600 }).animate({ transform: 'rotate(0deg)' }, { duration: 500 });
}

DDR.onSignHanging = function () {
    DDR.setUpShopSignHanger.css('z-index', 11000).click(DDR.signAway);
    if (DDR.transformCapable) $('.move-sign').mouseenter(DDR.moveSign).mouseleave(DDR.moveSign);
}

DDR.moveSign = function (evt) {
    DDR.setUpShopHangingSign.stop(true, false).animate({ transform: 'rotate(' + (evt.type == 'mouseenter' ? '25' : '-10') + 'deg)' }, { duration: 600 });
    if (evt.type == 'mouseleave') DDR.setUpShopHangingSign.animate({ transform: 'rotate(0deg)' }, { duration: 500 });
}

DDR.signAway = function () {
    if (DDR.transformCapable) {
        DDR.setUpShopSignHanger.css({ display: 'none' });
        DDR.setUpShopHangingSign.animate({ top: '200px', opacity: 0 }, { duration: 500, complete: DDR.remove });
    }
    else {
        DDR.setUpShopHangingSign.remove();
        DDR.setUpShopSignHanger.remove();
    }
}
/*=============set up shop 1-2012=============*/



DDR.searchformat = function () {
    if ($("#your-search-criteria").length > 0) {
        var height = $("#your-search-criteria").height();
       // alert(height);
        $("#increaseheight").css("height", height + 20);
    }
}
var artfeature;
DDR.artintheCommunity = function (el) {
    if(artfeature!=null){ 
        if(artfeature.images.length >= 1) {
            // alert("total images " + artfeature.images.length);
           //clear the images
            artfeature.images = [];

        }
    }
    //we bring up current selection
    var images = $(el).find(".images").html();
    var thumbs = $(el).find(".thumbs").html();
    $(".art-thunder-scroll-viewport").html(images);
    $(".art-slider").html(thumbs);

    if ($('.art-thunder-scroll-viewport img').size() > 1) {
        artfeature= thunder.client.modify.scrollFeatureArt(400, 3000, 500, 'art-');
        //alert("total images " + artfeature.images.length);

        var counting = 1;
        $('.art-slider > li').each(function () {
            //  $(this).append('<div class="count">' + count + '</div>');
            counting += 1;
        });
        $('.scrollIt-prev').unbind('click');
        $('.scrollIt-next').unbind('click');
        $('.art-slider').find('a').stop(true, true);
        if (counting > 4) {

            $('.art-slider').scrollIt({
                menuHeight: 85,
                menuWidth: 400,
                itemHeight: 75,
                itemWidth: 100,
                initialItem: 0
            });
            //alert("scrolling");
        } else {
            $('.scrollIt-arrow').css('display', 'none');
        }
    }


}

//DDR.linkedinShare = function (message, url) {
//    var xml = '<?xml version="1.0" encoding="UTF-8"?>';
//    xml = xml + '<share>';
//    xml = xml + '<comment>' + message + '</comment>';
//    xml = xml + '<content>';
//    xml = xml + '<title>' + message + '</title>';
//    xml = xml + '<submitted-url>' + url + '</submitted-url>';
//    xml = xml + '</content>';
//    xml = xml + '<visibility>';
//    xml = xml + '<code>anyone</code>';
//    xml = xml + '</visibility>';
//    xml = xml + '</share>';
////    alert(xml);
////    return;
//    $.ajax({
//        type: 'POST',
//        url: 'http://api.linkedin.com/v1/people/~/shares',
//        contentType: "text/xml",
//        processData: false,
//        data: xml,
//        dataType: "xml",
//        success: function (data) {
//            showMsg("LinkedIn Share Completed. Thank you.");
//        },
//        complete: function(data){
//            showMsg(data);
//        },
//        error: ddrConnect.requestError
//    });


//}



///used for employees as participants and community involvement
DDR.expandGallery = function (id) {
   
    //we bring up current selection
    var images = $("#images" + id).html();
    var thumbs = $("#thumbs" + id).html();
    $(".art-thunder-scroll-viewport").html(images);
    $(".art-slider").html(thumbs);

    if ($('.art-thunder-scroll-viewport img').size() > 1) {
        artfeature = thunder.client.modify.scrollFeatureArt(400, 3000, 500, 'art-');
 

        var counting = 1;
        $('.art-slider > li').each(function () {
            //  $(this).append('<div class="count">' + count + '</div>');
            counting += 1;
        });
        $('.scrollIt-prev').unbind('click');
        $('.scrollIt-next').unbind('click');
        $('.art-slider').find('a').stop(true, true);
        if (counting > 4) {

            $('.art-slider').scrollIt({
                menuHeight: 85,
                menuWidth: 400,
                itemHeight: 75,
                itemWidth: 100,
                initialItem: 0
            });
            //alert("scrolling");
        } else {
            $('.scrollIt-arrow').css('display', 'none');
        }
    }


}


//GETTING SLOPPY, BUT NEEDED.
thunder.client.modify.scrollFeatureArt = function (scrollImageWidth, scrollImageTime, scrollImageAnimationTime, areas, scrollCallback) {
    var _feature = {};
    _feature.counting = false;
    _feature.index = -1;
    _feature.direction = 1;
    _feature.precommence = function () {
        _feature.timeout = setTimeout(_feature.change, scrollImageTime);
        _feature.counting = true;
    }
    _feature.commence = function () {
        if (_feature.counting == true) {
            _feature.counting = false;
            clearTimeout(_feature.timeout);
        }
        _feature.change();
    }
    _feature.next = function () { _feature.direction = 1; _feature.commence(); }
    _feature.previous = function () { _feature.direction = -1; _feature.commence(); }
    _feature.change = function () {
        _feature.previndex = _feature.index;
        _feature.index += _feature.direction;
        if (_feature.index >= _feature.images.length) _feature.index = 0;
        if (_feature.index < 0) _feature.index = _feature.images.length - 1;
        _feature.scrollNow();
    }
    _feature.changeTo = function (newIndex) {
        clearTimeout(_feature.timeout);
        _feature.previndex = _feature.index;
        _feature.index = newIndex;
        if (_feature.index >= _feature.images.length) _feature.index = 0;
        if (_feature.index < 0) _feature.index = _feature.images.length - 1;
        if (_feature.index != _feature.previndex) _feature.scrollNow();
    }
    _feature.scrollNow = function () {
        if (scrollCallback) scrollCallback(_feature);
        if (_feature.previndex >= 0) {
            if (_feature.direction > 0)
                $(_feature.images[_feature.previndex]).animate({ 'left': 0 - scrollImageWidth }, { duration: scrollImageAnimationTime, queue: false });
            else
                $(_feature.images[_feature.previndex]).animate({ 'left': scrollImageWidth }, { duration: scrollImageAnimationTime, queue: false });
        }
        if (_feature.index >= 0) {
            if (_feature.direction > 0)
                _feature.images[_feature.index].style.left = scrollImageWidth + 'px';
            else
                _feature.images[_feature.index].style.left = '-' + scrollImageWidth + 'px';
            $(_feature.images[_feature.index]).animate({ 'left': 0 }, { duration: scrollImageAnimationTime * .95, queue: false });
        }
        //if there is a legend p, then we add the alt info to it
        if ($(".art-caption").length > 0) {
            $(".art-caption").html($(_feature.images[_feature.index]).attr("alt"));
        }

        _feature.precommence();
    }
    _feature.images = $('.' + areas + 'thunder-scroll-feature').children('.' + areas + 'thunder-scroll-viewport').find('img');
    _feature.images.css('left', '-' + scrollImageWidth + 'px');
    if (_feature.images.length > 0) {
        _feature.commence(); _feature.images[0].style.left = 0;
        $('.' + areas + 'arrowLeft').show();
        $('.' + areas + 'arrowRight').show();
    }
    $('.' + areas + 'thunder-scroll-feature').children('.' + areas + 'thunder-scroll-left').click(_feature.previous);
    $('.' + areas + 'thunder-scroll-feature').children('.' + areas + 'thunder-scroll-right').click(_feature.next);
    var count = 0;
    $('.' + areas + 'slider li a').each(function () {
        $(this).attr("alt", count);
        $(this).click(function () { _feature.changeTo($(this).attr("alt")); });

        count += 1;
    });
    return _feature;
};


DDR.highlightRectangle = function(evt)
{
	if(evt.type=='mouseenter')
	{
		$(this).addClass('highlight-blue').removeClass('highlight-white');
	}
	else
	{
		$(this).addClass('highlight-white').removeClass('highlight-blue');
	}
}

DDR.highlightPicRoll = function (evt) {
    if (evt.type == 'mouseenter') {
        $(this).addClass('piclight-grey').removeClass('piclight-white');
    }
    else {
        $(this).addClass('piclight-white').removeClass('piclight-grey');
    }
}
DDR.submitSUSRequest = function () {
    // alert("whooo");
    //we send request out to handler
    var name = $("#name").val();
    var email = $("#email").val();
    var phone = $("#home-phone").val();
    var message = $("#comments").val();
    var numb = $("#prop_numb").val();
    var unit = $("#unit").val();
    if (name == '' || email == '' || name=='Enter your name' || email=='Enter your email address' ) {
        showMsg('Please enter your name and email so we may follow up with you.');
        return false
    }
    $("#sus-contact-form").html('<h2>Processing...Please wait.</h2><img id="wheel" src="/themes/main/images/bigrotation2.gif"/> ');
   // $("#wheel").show();
    var url = "/listings/setupshoprequest.ashx?pn=" + numb + "&unit=" + unit + "&name=" + name + "&email=" + email + "&phone=" + phone + "&comments=" + message;
//    alert(url);
//    return false;
    $("#submit-btn").hide();
    $.ajax({
        type: "GET",
        url: url,
        complete: function () {
            // $("#submit-btn").show();
           // $("#wheel").hide();
            $("#sus-contact-form").html('<h2>Your request for additional information was successfully submitted. A DDR representative will respond to your request soon. Thank you.</h2>');
        },
        success: function (msg) {
            if (msg == '1') {
                //success

                //if we are plotting to a TBD then we throw in, if not, we swap
                showMsg('<h2>Your request for additional information was successfully submitted. A DDR representative will respond to your request soon. Thank you.</h2>');

            }
            else {

                showMsg('Sorry, please try again later. We are experiencing technical difficulties.');

            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {


            showMsg('Sorry, please try again later. We are experiencing technical difficulties.');
        }
    });


    return false;

}

DDR.SUSForm = function (pn, unit) {
   // alert("whooo");
    //we send request out to handler
    //if we are plotting to a TBD then we throw in, if not, we swap
    showMsg('<iframe  frameBorder="0" scrolling="no" src="/listings/setupshop.aspx?pn=' + pn + '&unit=' + unit +'" style="height:470px;width:550px;border:0px;overflow:hidden;"/></iframe>');


}


DDR.expandLink = function()
{
	DDR.expandLinks.not(this).removeClass('expand-link-active').stop(true, false).animate({marginTop: 0, marginBottom: 0}, {duration: 500}).children('div').slideUp(500);
	$(this).addClass('expand-link-active').stop(true, false).animate({marginTop: 19, marginBottom: 19}, {duration: 500}).children('div').slideDown(500);
}
DDR.expandsubLink = function () {
    DDR.expandsubLinks.not(this).removeClass('expand-sublink-active').stop(true, false).animate({ marginTop: 0, marginBottom: 0 }, { duration: 500 }).children('p').slideUp(500);
    $(this).addClass('expand-sublink-active').stop(true, false).animate({ marginTop: 19, marginBottom: 19 }, { duration: 500 }).children('p').slideDown(500);
}

DDR.expandLocator = function () {
  
    // alert(DDR.locator.css('display'));
    if (DDR.locatorLocked) return true;
    DDR.locatorLocked = true;
    var t = $(this);
    if (DDR.locator.css('display') == 'none') {
        t.find('#locator-arrow-down').slideUp(500);
        t.find('#locator-arrow-up').slideDown(500);
        DDR.locator.stop(true, false).slideDown(500, 'swing', DDR.unlockLocator);
        DDR.locator.children('#locator-advanced').stop(true, false).animate({ top: 9 }, { duration: 500 });
        //alert('not showing');
    }
    else {
        //alert('showing');
        t.find('#locator-arrow-down').slideDown(500);
        t.find('#locator-arrow-up').slideUp(500);
        DDR.locator.stop(true, false).slideUp(500, 'swing', DDR.unlockLocator);
        DDR.locator.children('#locator-advanced').stop(true, false).animate({ top: 0 }, { duration: 500 });
    }
}

DDR.unlockLocator = function () {
    DDR.locatorLocked = false;
    //alert("un locked");
}

//determine the current section (top nav section) by current page
DDR.applyCurrentMenu = function () {

    //loop through all breadcrumbs <a> elements
    $("#breadcrumbs > a").each(function () {
        //loop through top tier
        var found = $(this).attr("href");
        $("#menu > a").each(function () {
            //loop through top tier and if found, we have current section
            if ($(this).attr("href")==found) {
                $(this).addClass("active");
            }
        });
    });

}

DDR.quickLinkHover = function()
{
	var t = $(this);
	var w = t.width();
	if(w < 50) t.addClass('hovers-blue-50');
	else if(w < 75) t.addClass('hovers-blue-75');
	else if(w < 100) t.addClass('hovers-blue-100');
	else if(w < 125) t.addClass('hovers-blue-125');
	else if(w < 150) t.addClass('hovers-blue-150');
	else if(w < 175) t.addClass('hovers-blue-175');
	else if(w < 200) t.addClass('hovers-blue-200');
	else if(w < 225) t.addClass('hovers-blue-225');
	else if(w < 250) t.addClass('hovers-blue-250');
	else if(w < 275) t.addClass('hovers-blue-275');
	else if(w < 300) t.addClass('hovers-blue-300');
}

DDR.advancedSearch = function() {

    if (DDR.locatorLocked) return true;
    DDR.signAway();
	DDR.locatorLocked = true;
	if(this.id == 'advanced-search')
	{
		DDR.locator.stop(true, false).animate({width: 354}, {duration: 500, complete: DDR.unlockLocator});
	}
	else
	{
		DDR.locator.stop(true, false).animate({width: 168}, {duration: 500, complete: DDR.unlockLocator});
	}
	$(this).stop(true, true).slideUp(500).parent().children().not(this).stop(true, true).slideDown(500);
}

DDR.flashReplace = function()
{
	var so;
	so = new SWFObject("flash/swf1.swf", "swf-obj-1", "300", "250", "9", "");
	so.addParam("quality", "high");
	so.addParam("wmode", "transparent");
	so.write("swf-holder-1");
}
DDR.flashReplaceUSAMap = function () {
    var so = new SWFObject("ddrUSA2.swf", "ddrSwfMap", "730", "500", "9", "");
    so.addParam("quality", "high");
    so.addParam("wmode", "transparent");
    so.write("ddrSwfMapDivUSA");
}
DDR.flashReplaceBrazilMap = function () {
    var so = new SWFObject("ddrBrazil2.swf", "ddrSwfMap", "730", "500", "9", "");
    so.addParam("quality", "high");
    so.addParam("wmode", "transparent");
    so.write("ddrSwfMapDivBrazil");
}
DDR.flashReplaceValuText = function () {
    if (ua.iPad) {

//        $(".layout").css("width", "1020px");
//        $(".layout").css("padding", "0px 20px");
       // alert("you are on iPad");
    }
    //$('#ddrValuTextVideo5').show();
    //    VideoJS.setupAllWhenReady();
    //    if (ua.iPad) {
    //     

    //    } else {
    //        var so = new SWFObject("valutext-video/value-text-video.swf", "ddrValuTxt", "360", "233", "9", "");
    //        so.addParam("quality", "high");
    //        so.addParam("wmode", "transparent");
    //        so.write("ddrValuTextVideo");

    //    }

}
DDR.searchSite = function () {

    window.location = '/search/custom.aspx?search=' + $("#search-field").val();

}

DDR.emailtofriend = function (id) {

    showMsg('<iframe width="450" height="350" frameborder="0" src="/listings/emailtofriend.aspx?pn=' + id + '"></iframe>');

}
DDR.showphotos = function (id) {

    showMsg('<div style="width:575px;"><iframe width="550" height="410" scrolling="no" frameborder="0" src="/listings/photos.aspx?pn=' + id + '"></iframe></div>');

}
DDR.socialIconsHover = function () {

    $('.sharebutton').mouseover(function () { $('.sharebutton').fadeOut('fast'); });
    $('.sharebutton').mouseout(function () { $('.sharebutton').fadeIn('fast'); });

}

var sotarget;
var hasflash = true;
DDR.sustainabilityFlash = function () {
    
    sotarget = $('#content-element-4');

    if (sotarget.length > 0) {
        $('.sustainability-content').css('display', 'none');
        sotarget.css('position', 'relative').css('width', '100px').css('height', '333px');
        var so2 = new SWFObject("/themes/main/flash/sustainability.swf", "neo_swf_id", "775", "333", "9", "");
        so2.addParam("quality", "high");
        so2.addParam("wmode", "transparent");
        so2.addParam("allowScriptAccess", "always");
        hasflash = so2.write("content-element-4");
        if (!hasflash) sustainabilityIntroIsOver();
       // sotarget.children().css('position', 'absolute').css('left', '0px').css('top', '0px');
        MoveSearch();
        $('.ui-section-menu').click(function () {
            var greenMenus = $('.ui-section-menu');
            var greenSections = $('.sustainability-section');
            var greenSection = greenSections.eq(greenMenus.index(this));
            $(this).css('opacity', 0.4);
            greenMenus.not(this).css('opacity', 1);
            greenSection.css('display', 'block');
            greenSections.not(greenSection).css('display', 'none');
//            MoveSearch2(greenSection.height());
        }).eq(0).css('opacity', 0.4);
    }

    $('.get-flash-warning').css('display', 'block');


}

function sustainabilityIntroIsOver() {
    $('#content-element-4').css('display', 'none');
    $('.sustainability-content').css('display', 'block');
    $('.sustainability-section').eq(0).css('display', 'block');
    $('.sustainability-menu-last, .sustainability-menu').css('display', 'block');
}

function MoveSearch() {
    $('.hideflash').css('visibility', 'visible');
    // alert(sotarget.children('a').length);
    if (hasflash == false) { sotarget.css({ 'height': '800px' }); }
//    if ($.browser.msie) {
//        if ($.browser.version <= 6) {
//            $('#bottom_search').css('bottom', '80px');
//        }
//    }
}
/********LOCATOR**********************/

DDR.radiusSearch = function () {
    var postalcode = $("#ctl00_Locator1_ziptxt");
    var radius = $("#radius");
    if (postalcode.length > 0) {

        if (postalcode.val().length >= 5) {
            //we show
            radius.show('fast');
        }
        else {
            //we hide
            radius.hide('fast');
        }
    }
}

DDR.showDescription = function () {

    if ($("#propdescription").length > 0) {
        showMsg('<div style="width:400px;padding:50px;">' + $("#propdescription").html() + '</div>');
    }

}

var enterglobe = false;

DDR.enableEnterKey = function () {

    ///ENTER KEY FOR LOCATOR

    var $btn = $("#ctl00_Locator1_ImageButton1");
    var $search = $("#search-button");
    $("#search-field").keypress(function (e) {
        if (e.which == 13 && enterglobe == false) {
            enterglobe = true;
            $search.click();
            //e.preventDefault();
            return false;
        }
    });

    var ePreventDefault = function (e) { if (e.which == 13) { e.preventDefault(); return false; } }

    $("#locator input").each(function (i, item) {
        $(item).keypress(function (e) {
            if (e.which == 13 && enterglobe == false) {
                enterglobe = true;
                //alert('input' + $(item).attr("value"));
                $btn.click();
               // e.preventDefault();
                return false;
            }
        });
    });


    $("#locator select").each(function (i, item) {
        $(item).keypress(function (e) {
            if (e.which == 13 && enterglobe == false) {
                enterglobe = true;
                // alert('select' + $(item).attr("value"));
                $btn.click();
                // e.preventDefault();
                return false;
            }
        });
    });




}


function HideDropDownFunction()
{
 var searchradiusbox = document.getElementById("searchradiusbox");
 if(searchradiusbox){searchradiusbox.style.visibility="hidden";}
}




function checkPostalCode(){
   
}


 //    ///AUTOCOMPLETE
    function findValue(li) {
        if (li == null) return alert("No match!");

        // if coming from an AJAX call, let's use the CityId as the value
        if (!!li.extra) var sValue = li.extra[0];

        // otherwise, let's just display the value in the text box
        else var sValue = li.selectValue;

        // alert("The value you selected was: " + sValue);
    }

    function selectItem(li) {
        findValue(li);
    }

    function formatItem(row) {
        return row[0];
    }

    function lookupAjax() {
        var oSuggest = $("#ctl00_Locator1_propertynametxt")[0].autocompleter;
        oSuggest.findValue();
        return false;
    }

    function lookupLocal() {
        var oSuggest = $("#CityLocal")[0].autocompleter;

        oSuggest.findValue();

        return false;
    }
    DDR.resetLocator = function () {
        $(':input', '#locator')
        .not(':button, :submit, :reset, :hidden')
        .val('')
        .removeAttr('checked')
        .removeAttr('selected');
        $("#radius").hide('fast');

    }
    DDR.autocomplete = function () {

        if ($("#ctl00_Locator1_propertynametxt").length > 0) {
            $("#ctl00_Locator1_propertynametxt").autocomplete(
    "/service/autocomplete.ashx",
        {
            delay: 10,
            minChars: 2,
            matchSubset: 1,
            matchContains: 1,
            cacheLength: 10,
            onItemSelect: selectItem,
            onFindValue: findValue,
            formatItem: formatItem,
            autoFill: true,
            width: 250
        }
    );
        }
    }

/*===========================END OF LOCATOR SPECIFICS===============*/
function showMsg(message) {

  var j = $(this).jBox();
    //    var myImg = new Image();

    //    $(myImg).load(function () {


    //        // alert(myImg.src);
    //        j.position();

    //    });
    //    myImg.src = img;
    j.showWindow('<div id="msgbox">' + message + '</div>');


}
  
    /*===more legacy misc functions ===============*/

function openImage(img) {

   // $(this).jBox().showWindow('<div id="msgbox"><img src="' + img + '"/></div>');
    var j = $(this).jBox();
//    var myImg = new Image();

//    $(myImg).load(function () {


//        // alert(myImg.src);
//        j.position();

//    });
//    myImg.src = img;
    j.showWindow('<div id="msgbox"><iframe height="400" width="350" frameborder="0" src="' + img + '"/></iframe></div>');
}
//home page new branding welcome
var brandwelcome = null;
DDR.newBrandOpening = function () {
    brandwelcome = $(this).jBox({ 'showClose': false, 'fadeInDelay': 700, 'border': '2px solid #818a8f', 'fixedWidth': $(window).width() * .96 });
    //    var myImg = new Image();

    //    $(myImg).load(function () {


    //        // alert(myImg.src);
    //        j.position();

    //    });
    //    myImg.src = img;

    brandwelcome.showWindow('<div id="msgbox" style="text-align:center;"><div style="width:700px;margin:auto auto;"><a onclick="brandwelcome.close();" style="float:right;width:100px;display:block;cursor:pointer;">Enter Site</a><br style="clear:both;"/><iframe frameborder="0" style="width:650px;height:400px;" src="/themes/main/images/Website_Curtain_Graphic_v2.png"/></div></div>');

}

var DDRSimpleSlideshow = {};
var duration = 4500;
var durationfade = 2000;
DDRSimpleSlideshow.onReady = function () {
    if ($('#simple-slideshow').find('a').length > 1) {
        DDRSimpleSlideshow.images = $('#simple-slideshow').find('a').css({ opacity: 0 });
        DDRSimpleSlideshow.index = 0;
        clearInterval(DDRSimpleSlideshow.onTimer);
        setInterval(DDRSimpleSlideshow.onTimer, duration);
    }
}
DDRSimpleSlideshow.onTimer = function () {
    DDRSimpleSlideshow.index = (DDRSimpleSlideshow.index >= DDRSimpleSlideshow.images.length - 1) ? 0 : DDRSimpleSlideshow.index + 1;
    $('#simple-slideshow').find('a').css("z-index", "0")
    DDRSimpleSlideshow.images.not(DDRSimpleSlideshow.images.eq(DDRSimpleSlideshow.index).animate({ opacity: 0 }, { duration: durationfade })).animate({ opacity: 1 }, { duration: durationfade }).css("z-index","9999");
}

var DDRHomeSlideshow = {};
var durationH = 5000;
var durationfade = 2000;
DDRHomeSlideshow.onReady = function () {
    if ($('#promos').find('#promo').length > 1) {
        DDRHomeSlideshow.images = $('#promos').find('#promo');
        DDRHomeSlideshow.index = 0;
       // clearInterval(DDRHomeSlideshow.onTimer);
        setInterval(DDRHomeSlideshow.onTimer, durationH);
    }
}
DDRHomeSlideshow.onTimer = function () {
    DDRHomeSlideshow.index = (DDRHomeSlideshow.index >= DDRHomeSlideshow.images.length - 1) ? 0 : DDRHomeSlideshow.index + 1;
    $('#promos').find('#promo').css("filter", "");
    DDRHomeSlideshow.images.not(DDRHomeSlideshow.images.eq(DDRHomeSlideshow.index).animate({ opacity: 0 }, { duration: durationfade }).css("z-index", "0")).animate({ opacity: 1 }, { duration: durationfade }).css("z-index", "9999").css("display", "block").css("filter", "");
     //DDRHomeSlideshow.images.not(DDRHomeSlideshow.images.eq(DDRHomeSlideshow.index).hide('fast')).show('fast');


    //DDRHomeSlideshow.images.not(DDRHomeSlideshow.images.eq(DDRHomeSlideshow.index).customFadeOut(durationH)).customFadeIn(durationH);
}




$(document).ready(DDR.pageLoaded);
