﻿function pageLoad(sender, args) {
    $('.communityList').jcarousel();
    $('.carouselSingleSelect').jcarousel();
    $('.carouselMultiSelect').jcarousel();
    

     $('.thumbSlider li').click(function() {
        // Grab the checkbox contained inside the list item
        checkbox = $(this).find('input');

        // If the clicked checkbox is checked, then remove the highlight and postback the value
        if (checkbox.get(0).checked) {

            $(this).removeClass('selected');
            checkbox.attr('checked', false);

            // Get name from input and pass to .NET Javascript
            checkid = checkbox.attr('name');
            if ($(this).parent().hasClass('carouselSingleSelect') || $(this).parent().attr('id') == 'CarouselPrimary') {
                __doPostBack(checkid, '');
            }

        } else {

            checkid = checkbox.attr('name');

            if ($(this).parent().hasClass('carouselSingleSelect') || $(this).parent().attr('id') == 'CarouselPrimary') {
                uncheckAll(checkid);
            }

            // Highlight the selected and check the box
            $(this).addClass('selected');
            checkbox.attr('checked', true);

            // Get name from input and pass to .NET Javascript

            if ($(this).parent().hasClass('carouselSingleSelect') || $(this).parent().attr('id') == 'CarouselPrimary') {
                __doPostBack(checkid, '');
            }
        }
    });
}

$(document).ready(function($) {

    if (!$.browser.opera) {
        // select element styling
        $('.avi_select').each(function() {
            var title = $(this).attr('title');
            var selectwidth = $(this).width();

            if ($('option:selected', this).val() != '') title = $('option:selected', this).text();

            $(this)
					    .css({ 'z-index': 10, 'opacity': 0, '-khtml-appearance': 'none' })
					    .after('<span class="avi_select" style="width:' + (selectwidth) + 'px;">' + title + '</span>')
					    .change(function() {
					        val = $('option:selected', this).text();
					        $(this).next().text(val);
					    })
        });
    };
    
    $(".txtBox").focus(function(srcc) {
        if ($(this).val() == $(this)[0].title) {
            $(this).removeClass("txtBoxActive");
            $(this).val("");
        }
    });

    $(".txtBox").blur(function() {
        if ($(this).val() == "") {
            $(this).addClass("txtBoxActive");
            $(this).val($(this)[0].title);
        }
    });

    $(".txtBox").blur();

    /** Admin - Home Styles Packagas Sliders **/
    /*$('#CarouselRender').jcarousel();
    $('#CarouselExterior').jcarousel();
    $('#CarouselInterior').jcarousel();
    $('#CarouselPrimary').jcarousel();      
    $('#CarouselQuickPossessionExterior').jcarousel();
    $('#CarouselQuickPossessionsInterior').jcarousel();
  

    $('.carouselSingleSelect').jcarousel();
    $('.carouselMultiSelect').jcarousel();
    */
    $('.thumbSlider li').wrapInner(function() {
        checkbox = $(this).find('input');
        checkid = checkbox.attr('name');
        return '<label for="' + checkid + '" />';
    });

    // Add rounded corners to buttons for IE7/IE8
    $('.orangeBtn').corner("5px");

    // Fix the flicker effect in IE7/IE8
    $('.orangeBtn input').hover(
        function() {
            $(this).parent().css('background-position', '0 -39px');
        },
        function() {
            $(this).parent().css('background-position', '0 0');
        }
    );

    mainNav();
    highlightChecked();

    // Because IE7 can't handle :active state
    $('.selectboxAlt').click(function() {
        $(this).toggleClass("selectboxAltActive");
    });

    $(".selectboxAlt").blur(function() {
        $(this).removeClass("selectboxAltActive");
    });


    //$('.customDD').selectbox();

    /* Live Chat popup
    $('#ctaPopQuestions').hide();
    $('#ctaQuestions').click(function() {
    $('#ctaPopQuestions').slideToggle('500');
    return false;
    });
    */

    if ($('.actionButtons_Save').length) {
        // Adjust CSS to make admin panel fit properly in home page
        $('#homeSide').css('padding', '35px 62px 30px 18px');
    }

    $('#chooseHomeStyleList li a.link').mouseover(function() {
        $(this).next('.graphic').show();
    });
    $('#chooseHomeStyleList li a.link').mouseout(function() {
        $(this).next('.graphic').hide();
    });

    $(".selectRender").click(function() {
        $(this).css("visibility:hidden;");
    });


    $('.thumbSlider li').hover(function() {
        if (!$(this).find('input').get(0).checked) {
            $(this).find('div').addClass('selected');
        }
    }, function() {
        if (!$(this).find('input').get(0).checked) {
            $(this).find('div').removeClass('selected');
        }
    });

});

// Highlight the checked photos
function highlightChecked() {
    $('.jcarousel-item input[type=checkbox]').each(function() {
        if (this.checked) {
            $(this).parent().parent().addClass('selected');
        }
    });
}

function uncheckAll(checkexception) {

    $('.carouselSingleSelect .jcarousel-item input[type=checkbox]').each(function() {
        if (this.checked) {

            //alert('ATTRIBUTE NAME ' + $(this).attr('name'));
            //alert('CHECK EXCEPTION ' + checkexception); 

            $(this).parent().parent().parent().removeClass('selected');
        }
    });
}

//Top Nav
function mainNav() {
    $(" #mainNav li div.flyOut ").css({ display: "none" }); // Opera Fix
    $(" #mainNav li").hover(function() {
        $(this).find('div:first').css({ visibility: "visible", display: "none" }).show(400);
    }, function() {
        $(this).find('div:first').css({ visibility: "hidden" });
    });
}





