// Skin Specific JS goes here. The jQuery library has already been loaded by the core templates. So if you use jQuery, you are ready to go.


jQuery(window).load(function() {
	// Ensure that all content areas are equal height
	jQuery('#pageWrap').each(function(){
		var maxHeight = 0;
		jQuery(this).children('div[id^=contentBlock], div[id^=generatedContent]').each(function() {
			if (jQuery(this).height() > maxHeight) {
				maxHeight = jQuery(this).height();
			}
		});
		if (maxHeight) {
			// Only update the generated content height since its less likely to have DOM changes after load.
			// @todo Need a more robust way to set the height for all columns while still allowing resize after DOM changes.
			jQuery(this).children('div[id^=generatedContent]').height(maxHeight + 'px');
		}
	});
	
	//slide gallery js
	var container = jQuery('div.sliderGallery');
    var ul = jQuery('ul', container);
	var itemsWidth = ul.innerWidth() - container.outerWidth();
        jQuery('.slider', container).slider({
                min: 0,
                max: itemsWidth,
                handle: '.handle',
                stop: function (event, ui) {
                    ul.animate({'left' : ui.value * -1}, 500);
                },
                slide: function (event, ui) {
                    ul.css('left', ui.value * -1);
                }
        });
	
	
});


jQuery(document).ready(function() {
	// Clear default search text on click.
	if (jQuery('#siteSearchInput').length > 0) {
		defaultSearchValue = jQuery('#siteSearchInput')[0].value;
		jQuery('#siteSearchInput').focus(function() {
			if (jQuery(this)[0].value === defaultSearchValue) {
				jQuery(this)[0].value = '';
			}
		});
		jQuery('#siteSearchInput').blur(function() {
			if (jQuery(this)[0].value === '') {
				jQuery(this)[0].value = defaultSearchValue;
			}
		});
	}
});



//Simple jQuery Slideshow Script
function slideSwitch() {
    var $active = $('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

