// JavaScript Document
jQuery.noConflict();

jQuery(document).ready(function() {
	initializeFooterCarousel();
	initializeHomeSlider();
	if(jQuery('#products-grid-table').length) evenGrid();
	jQuery('.colorbox-video').colorbox({transition:'fade', speed:500, iframe:true, width:'642px', height:'386px', onOpen: function() { jQuery('#cboxContent').removeClass('loaded'); }, onComplete: function() { jQuery('#cboxContent').addClass('loaded'); }});
	resetFields();
});

// Initialize the footer carousel that's on every page
function initializeFooterCarousel() {
	jQuery('.footer-carousel').jcarousel();
}

var homeSlider=null; // Store the homepage slider

// Initialize the homepage slider
function initializeHomeSlider() {
	if (document.getElementById('slider-holder')) {
		homeSlider=new slider();
	}
}

// Reset form fields on focus
function resetFields() {
	var inputArray = jQuery('input');
	for(i=0;i<inputArray.length;i++){
		if(inputArray[i].type == 'text') {
			inputArray[i].onfocus = function() {
				if (this.value == this.defaultValue) this.value = '';
			}
			inputArray[i].onblur = function() {
				if(this.value == '') this.value = this.defaultValue;
			}
		}
	}
}
	
// Make div's the full height of the row on the grid view
function evenGrid() {
	jQuery('#products-grid-table .grid-block').each(function() {
		var padding = jQuery(this).parent().css('paddingBottom').replace('px', '');
		jQuery(this).css('height', jQuery(this).parent().height()-padding+'px');
	});
}

// Swaps the thumbnail source with the main image on the media page
function thumbSwap() {
	jQuery('.image-thumb img').each(function() {
		jQuery(this).click(function() {
			var thumb_rel = jQuery(this).attr('rel');
			var thumb_array = thumb_rel.split('|');
			var thumb_view = thumb_array[0];
			var thumb_full = thumb_array[1];

			var img = jQuery('#image');
			img.attr('rel', thumb_rel);

			img.attr('src', thumb_view);
			jQuery('.colorboxImg').colorbox({transition:'fade', speed:500, href:thumb_full, onOpen: function() { jQuery('#cboxContent').removeClass('loaded'); }, onComplete: function() { jQuery('#cboxContent').addClass('loaded'); }});
			return false;
		});
	});

}
