/* Intel Gadget Store - scripts.js */


/* long-form js goes here */


/* jQuery plugins */

/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element 
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units 
 		by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article: 
		http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
 * Usage Example: $(element).equalHeights();
  		Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
 * Version: 2.0, 08.01.2008
--------------------------------------------------------------------*/

$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};



;(function($) {
	$.fn.fieldHint = function(options) {
		var opts = $.extend({
			hint: this.val(),
			useClass: true,
			defaultClass: 'default'
		},options);
		return this.each(function() {
			if( $(this).val() != opts.hint ) { $(this).val(opts.hint); }
			if ( ($(this).val() == opts.hint) && (opts.useClass) ) { $(this).addClass(opts.defaultClass); }
			$(this).focus(function() {
				if ( $(this).val() == opts.hint ) {
					$(this).val('');
					if ( opts.useClass ) { $(this).removeClass(opts.defaultClass); }
				}
			});
			$(this).blur(function() {
				if ( $(this).val() == '' ) {
					$(this).val(opts.hint);
					if ( opts.useClass ) { $(this).addClass(opts.defaultClass); }
				}
			});
		});
	};
})(jQuery);



$(function(){ /* arbitrary jQuery code goes inside here */


	// search inputs
	$('form.search input.text').fieldHint({'hint': 'Search'});


	// homepage slideshow
	$('body.home div.svSlides dl').each(function(){

		//find the IMG in DD.summary and apply it to the parent DL slide
		$(this).css({'background-image': 'url(' + $(this).find('dd.summary img').attr('src') + ')'});
		
		//remove the IMG in DD.summary
		$(this).find('dd.summary img').remove();
	});


	// heights
	// $('.tabs .section .gadgetList').equalHeights();



	// tabs
	$('div.tabs').tabs({
		select: function(event, ui) {$('.spinner').hide()}
	});
	
	function ajaxLoad(panel) {
		$('.navPagination a', panel).click(function() {
			$('.spinner').show();
			$(panel).load(this.href, function(){ajaxLoad(panel)});
			return false;
		});
	}
	ajaxLoad($('#all'));
	ajaxLoad($('#featured'));
	ajaxLoad($('#recently-added'));
	ajaxLoad($('#highest-rated'));
	ajaxLoad($('#most-downloaded'));


	// sIFR - prevent firing on these elements:
	$('.gadgetDetail .tabs .section h3, #svSearchResults dd h3, .feature h3').addClass('sIFR-ignore');


});



$(window).load(function(){ /* wait for images to be loaded before firing js */

});



/* EOF */

