_PFX = 'ctl00_C_';
_PPFX = '#ctl00_C_';
var slideShowDivs = null;
var slideShowOrder;
var menuSelectCount = 0;
var currentSliderOpen = 0;
var kimFound = 0;

// start Jquery stuff

var currentEvents = null;
$(function () {

    $('#menubar li').hover(function () {             //show its submenu 

        if (this.parentNode.id == "menubar") {
            //debugger;

            $('ul', this).slideDown(100);

        }
        else {
            //debugger;
            $('ul li', this).slideUp(100);
            $('ul li', this).css({ 'display': 'inline' });


        }
    },
       function () {             //hide its submenu 
           $('ul', this).slideUp(100);
       }
       );




    $('#submenubar li').hover(function () {             //show its submenu 


        if (this.parentNode.id == "submenubar") {
            //debugger;
            $('ul', this).slideDown(100);

        }
        else {
            //debugger;
            $('ul li', this).slideUp(100);
            $('ul li', this).css({ 'display': 'inline' });


        }
    },
       function () {             //hide its submenu 
           $('ul', this).slideUp(100);
       }
       );

     if ($('#ctl00_waldo').css('display') == 'block' || $('#ctl00_waldo').css('display') == 'inline' ) {
$('div#kimPopup').click(function() {document.location.href='http://www.grcc.com/View.aspx?page=chamber/contest';});

        $('#ReallyRealContent').hover(function () {
	if (kimFound == 0)
	{
	kimFound = 1;
            $('div#kimPopup').show("slide", { direction: "up" }, 300);
            // $('div#kimPopup').effect("bounce", { times: 3 }, 300);
	}
        },
        function () {
        }
        );
    }

    LeftPanel_OnLoad();
    //ChildrenGallery_OnLoad();
    //ChildrenVertical_OnLoad();
    CMSSlider_OnLoad();
    AutoHover_OnLoad();
    Watermark_OnLoad();
    SetTextSize($.cookie('textSize'));
    SlideShow_OnLoad();
    MenuMarker_OnLoad(0, -4);
    subMenuMarker_OnLoad(0, 0);
    Calendar_OnLoad();
    Gallery_OnLoad();




});



AutoHover_OnLoad =
	function () {
	    // activate any autohover images within the content

	    $('img.autohover, a.autohover img').each(function (index) {
	        $(this).attr('nsrc', $(this).attr('src'));
	        $(this).attr('hsrc', $(this).attr('src').replace(/\.gif/, '_hover.gif').replace(/\.jpg/, '_hover.jpg').replace(/\.png/, '_hover.png'));
	    });

	    $("img[hsrc]").mouseover(function () {
	        var selected = getAttribute('boolean', this, 'selected', false);
	        if (!selected) {
	            var newSrc = getAttribute('string', this, 'hsrc', '');
	            if (newSrc.length > 0) {
	                this.src = newSrc;
	                var x = new Image();
	                x.src = newSrc;
	            }
	        }
	    });
	    $("img[nsrc]").mouseout(function () {
	        var selected = getAttribute('boolean', this, 'selected', false);
	        if (!selected) {
	            var newSrc = getAttribute('string', this, 'nsrc', '');
	            if (newSrc.length > 0) this.src = newSrc;
	        }
	    });

	}

	Calendar_OnLoad =
    function () {

        if ($('#calendar').size() == 0) return;

        // load calandar events

        // first just load the first months events so calendar can render quickly

        var now = new Date();
        var calendarMinDate = new Date(now.getFullYear(), now.getMonth(), 1); // don't show earlier than first day of this month
        var calendarMaxDate = new Date(now.getFullYear() + 1, now.getMonth() + 1, 1);  // don't show later than last day of month one year in advance
        calendarMaxDate = new Date(calendarMaxDate.getTime() - 1000 * 60 * 60 * 24);

        var eventParams = new Object();
        eventParams.MonthToGet = now.getMonth() + 1;
        eventParams.YearToGet = now.getFullYear();

        $.ajax({
            type: 'POST',
            url: '/Services.asmx',
            data: ajaxSoapRequest('GetMonthsEvents', eventParams),
            contentType: "text/xml;",
            success: function (data, status, xhr) {
                if (status == 'success') {
                    var totaljson = data.getElementsByTagName("GetMonthsEventsResult")[0].firstChild.nodeValue;
                    if (data.getElementsByTagName("GetMonthsEventsResult")[0].textContent != undefined) totaljson = data.getElementsByTagName("GetMonthsEventsResult")[0].textContent;
                    currentEvents = $.parseJSON(totaljson);
                    $("#calendar").datepicker({ minDate: calendarMinDate, maxDate: calendarMaxDate, beforeShowDay: highlightEvents, onSelect: calendarSelected });

                    // now load all months

                    $.ajax({
                        type: 'POST',
                        url: '/Services.asmx',
                        data: ajaxSoapRequest('GetAllEvents', null),
                        contentType: "text/xml;",
                        success: function (data, status, xhr) {
                            if (status == 'success') {
                                var totaljson = data.getElementsByTagName("GetAllEventsResult")[0].firstChild.nodeValue;
                                if (data.getElementsByTagName("GetAllEventsResult")[0].textContent != undefined) totaljson = data.getElementsByTagName("GetAllEventsResult")[0].textContent;
                                currentEvents = $.parseJSON(totaljson);
                            }
                        }
                    });

                }
            }
        });

    }


calendarSelected =
    function (dateText, inst) {
        if (currentEvents == null) return;
        var id = 0;
        var date = parseMDY(dateText);
        for (var i = 0; i < currentEvents.length; i++) {
            var thisDate = parseMDY(currentEvents[i].StartDate);
            if (date.getDate() == thisDate.getDate() && date.getMonth() == thisDate.getMonth() && date.getFullYear() == thisDate.getFullYear()) {
                if (id > 0) {
                    document.location.href = "/Membee.aspx?title=Upcoming%20Events&page=events&url=" + escape("http://memberservices.membee.com/variccoc/irmevents.aspx?pg=results&day=" + dateText);
                    return;
                }
                id = currentEvents[i].Id;
            }
        }
        if (id > 0) document.location.href = "/Membee.aspx?title=Upcoming%20Events&page=events&url=" + escape("http://memberservices.membee.com/variccoc/irmevents.aspx?id=" + id.toString());
    }

Gallery_OnLoad =
    function () {
        if ($('#gallery').size() == 0) return;
        $('#gallery').galleria({
            width: 700,
            height: 400,
            extend: function (options) {
                //$('.galleria-info').width
                $('.galleria-info-link').hide();
                $('.galleria-info-text').show();
                $('.galleria-info-close').hide();
            }
        });
    }

Go_OnClick =
	function () {
	    document.search.submit();
	}

highlightEvents =
    function (date) {
        if (currentEvents == null) return [true, ""];

        var tooltip = "";
        for (var i = 0; i < currentEvents.length; i++) {
            var thisDate = parseMDY(currentEvents[i].StartDate);
            if (date.getDate() == thisDate.getDate() && date.getMonth() == thisDate.getMonth() && date.getFullYear() == thisDate.getFullYear()) {
                if (tooltip.length > 0) tooltip += "\n\n";
                tooltip += currentEvents[i].Title;
            }
        }
        if (tooltip.length > 0) return [true, "dateHasEvent", tooltip];
        return [true, ""];
    }



SetTextSize =
	function (setting) {
	    if (setting == null) setting = 0;
	    var elSize = $('#textsize');
	    if (elSize.size() < 1) return;
	    var elImg = elSize.get(0).getElementsByTagName('img');
	    var elSide = $('#SidePanel');
	    var elMain = $('#RealContent');

	    if (setting == 0) {
	        elMain.removeClass('BIG');
	        if (elSide.size() > 0) elSide.removeClass('BIG');
	        $.cookie('textSize', 0);
	        elImg[0].src = elImg[0].src.replace(/enabled/, 'disabled');
	        elImg[1].src = elImg[1].src.replace(/disabled/, 'enabled');
	    }
	    if (setting == 1) {
	        var alreadyBig = elMain.hasClass('BIG');
	        if (!(alreadyBig)) elMain.addClass('BIG');
	        if (elSide.size() > 0) {
	            alreadyBig = elSide.hasClass('BIG');
	            if (!(alreadyBig)) elSide.addClass('BIG');
	        }
	        $.cookie('textSize', 1);
	        elImg[0].src = elImg[0].src.replace(/disabled/, 'enabled');
	        elImg[1].src = elImg[1].src.replace(/enabled/, 'disabled');
	    }
	}


SlideShow_OnLoad =
	function () {

	    slideShowDivs = $('div.slideshow');

	    if (slideShowDivs.size() > 0) {
	        slideShowOrder = new Array(slideShowDivs.size() - 1);
	        for (var i = 0; i < slideShowDivs.size(); i++) {
	            slideShowOrder[i] = i;
	            var xy;
	            if (i == 0) {
	                xy = $(slideShowDivs.get(i)).offset();
	            }
	            else {
	                $(slideShowDivs.get(i)).offset(xy)
	                $(slideShowDivs.get(i)).css('display', 'none');
	            }
	        }
	        SlideShow_Randomize();
	        setTimeout('SlideShow_Transition()', 4000);
	    }
	}

SlideShow_Transition =
	function () {
	    var oldLayer = slideShowDivs[slideShowOrder[lastSlideShowIndex]];
	    lastSlideShowIndex++;
	    if (lastSlideShowIndex >= slideShowDivs.length) {
	        lastSlideShowIndex = 0;
	        SlideShow_Randomize();
	    }
	    var newLayer = slideShowDivs[slideShowOrder[lastSlideShowIndex]];

	    $(oldLayer).fadeOut(1000, function () {
	        $(oldLayer).css('visible', 'hidden');
	        if (lastSlideShowIndex != 1) $(oldLayer).css('display', 'none');
	    });
	    if (lastSlideShowIndex != 0) $(newLayer).css('display', 'block');
	    $(newLayer).css('visible', 'visible');
	    $(newLayer).fadeIn(1000);

	    setTimeout('SlideShow_Transition()', 10000);

	}

SlideShow_Randomize =
	function () {
	    slideShowOrder.shift();
	    slideShowOrder.sort(RandomOrder);
	    slideShowOrder.unshift(0);
	}

Watermark_OnLoad =
    function () {
        $('input[watermark]').focus(function () {
            var watermark = getAttribute('string', this, 'watermark', '');
            if (watermark.length > 0 && watermark == $(this).val()) $(this).val('');
        });
        $('input[watermark]').blur(function () {
            if ($(this).val() == '') $(this).val(getAttribute('string', this, 'watermark', ''))
        });
    }

DDI_Web_TextBox_ValidateMinLength =
	function (oSrc, args) {
	    args.IsValid = true;
	    var el = $('#' + oSrc.id.replace(_LEN, '')).get(0);
	    var minLength = getAttribute('int', el, 'minlength', 0);
	    if (minLength > 0 && el.value.length > 0 && el.value.length < minLength) args.IsValid = false;
	}

	MenuMarker_OnLoad =
	function (additionalTopOffset, additionalLeftOffset) {
	    // if a menu is selected, indicate with a marker underneath it

         var mFound = false;
	    $('#menubar a').each(function (idx, item) {
	        //debugger;
	        var itemCenter = item.offsetWidth / 2;
	        var itemHeight = item.offsetHeight;
	       


	        var marker = $("#menumarker");

	        if (item.className == "Selected" && mFound==false) {
	            //debugger;

	            var coords = findPos(item);
	            var ieversion = 0;

	            if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
	                ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
	            }
	            if (ieversion == 7) {
	                itemHeight = itemHeight - 5; //darn IE7
	                marker.css("z-index", "20");
	                
	            }
	            if (coords[0] != 0 && coords[1] != 0) {
	                marker.css("left", coords[0] + itemCenter - 10);
	                marker.css("top", coords[1] + itemHeight);
	                marker.css("display", "inline");
	                mFound = true;
	            }

	        }
	        else {


	        }

	    });

	};

	subMenuMarker_OnLoad =
	function (additionalTopOffset, additionalLeftOffset) {
	    // if a menu is selected, indicate with a marker underneath it

	    var found = false;
	    $('#submenubar a').each(function (subidx, subitem) {
	        //debugger;
	        var subitemCenter = subitem.offsetWidth / 2;
	        var subitemHeight = subitem.offsetHeight - 1;

	        var submarker = $("#submenumarker");

	        if (subitem.className == "Selected") {
	            //debugger;

	            var subcoords = findPos(subitem);
	            var ieversion = 0;

	            if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
	                ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
	            }
	            if (ieversion == 7) {
	                subitemHeight = subitemHeight - 5; //darn IE7
	                submarker.css("z-index", "20");

	            }


	            submarker.css("left", subcoords[0] + subitemCenter - 5);
	            submarker.css("top", subcoords[1] + subitemHeight);
	            if (subcoords[1] + subitemHeight < 145 && subcoords[1] + subitemHeight > 10) {
	                submarker.css("display", "inline");
	            }
	            if (subitemHeight <= 0) {
	                submarker.css("display", "none");
	            }

	            found = true;


	        }
	        else {
	            if (found == false) {
	                submarker.css("display", "none");
	            }

	        }

	    });

	};

CMSSlider_OnLoad =
    function () {
        if ($('#ctl00_CMSSlider').size() > 0) {
            $(".CMSSliderList").hrzAccordion({ containerClass: "container3",
                listItemClass: "listItem3",
                openOnLoad: 1,
                contentWrapper: "contentWrapper3",
                handlePositionArray: "right,right,right,right,right",
                contentInnerWrapper: "contentInnerWrapper3",
                handleClass: "handle3",
                handleClassOver: "handleOver3",
                handleClassSelected: "handleSelected3"
            });
            ToggleSlider(1);
        } else {
            var sliderTop = parseInt($('#secondaryNav').css('top')) + parseInt($('#secondaryNav').css('height'));
            $('#middle').css('top', sliderTop + 'px');
            //$('#left').css('top', sliderTop + 'px');
        }
    }

CMSSlider_Click =
    function (direction) {
        //debugger;
        var NextSlide
        var maxSlideIdx = $('ul.CMSSliderList li').size() - 1;
        var handleID


        if (direction == "RIGHT") {

            NextSlide = currentSliderOpen + 1;

            if (NextSlide > maxSlideIdx) {
                NextSlide = 0;
            }


        }


        if (direction == "LEFT") {

            NextSlide = currentSliderOpen - 1;

            if (NextSlide < 0) {
                NextSlide = maxSlideIdx;
            }


        }

        handleID = "#" + "CMSSliderListHandle" + NextSlide;
        currentSliderOpen = NextSlide;
        $(handleID).click();



    }

var sliderTop = 0;
var middleTop = 0;

ToggleSlider =
    function (onload) {
        // load the current status of the slider
        var showIt = $.cookie('showSlider');
        // if nothing there, then we want to show it
        if (showIt == undefined || showIt == null || showIt == '') showIt = '1';
        showIt = parseInt(showIt);
        // if not loading page, we are toggling the current state
        if (onload == 0) {
            showIt = Math.abs(showIt - 1);
        } else {
            sliderTop = $('#ctl00_CMSSlider').css('top');
            middleTop = $('#middle').css('top');
            $('#middle').css('margin-top', '0');
        }

        if (showIt == 0) {
            $('#ctl00_CMSSlider').css('display', 'none');
            $('#ctl00_SliderToggle a').text('Show Panel');
            $('#middle').css('top', sliderTop);
            $('#middle').css('margin-top', '1');
            //$('#left').css('top', sliderTop);
        } else {
            $('#ctl00_CMSSlider').css('display', 'block');
            $('#ctl00_SliderToggle a').text('Hide Panel');
            if (onload == 0) {
                $('#middle').css('top', middleTop);
                $('#middle').css('margin-top', '0');
                //$('#left').css('top', middleTop);
            }
        }

        $.cookie('showSlider', showIt);

    }

function findPos(obj) {
    //debugger;
    var curleft = curtop = 0;

    if (obj.offsetParent) {
        do {
            if (obj.id == "wrap") {
                return [curleft, curtop];
            }
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;

        } while (obj = obj.offsetParent);
    }
    return [curleft, curtop];
}

function LeftPanel_OnLoad()
{
    var reallyrealcontentheight
    var leftheight
    //debugger;
    reallyrealcontentheight = $('#ReallyRealContent').height();
    leftheight = $('#left').height() ;


    if (reallyrealcontentheight > leftheight + 50) {
        $('#left').css('height', reallyrealcontentheight + 50);

    }
    else {

        $('#left').css('bottom', '0px;');

    }

    

}

