/*================================
 Duck Brand
 
 Last Updated By: Ryan Perry
 Last Updated: 11/30/2011
================================*/
jQuery(document).ready(function($){


/*================================================
 Cufon
================================================*/	
/*---- Toonish ----*/
Cufon.replace('#promotion-content.home h1:not(.no-cufon)', {fontFamily: 'Toonish', textShadow: '1px 1px 2px #acb496' });   
Cufon.replace('.toonish:not(.no-cufon)', {fontFamily: 'Toonish', textShadow: '1px 1px 2px #acb496' });   
Cufon.replace('#promotion-content.home h3:not(.no-cufon)', {fontFamily: 'Toonish', textShadow: '1px 1px 2px #acb496' });   
Cufon.replace('div#main.stuck-at-prom div#promotion-content.home div#sap-countdown div.display:not(.no-cufon)', {fontFamily: 'Toonish', textShadow: '1px 1px 2px #acb496' });   


/*---- MyriadPro ----*/
Cufon.replace('.myriad:not(.no-cufon)', {fontFamily: 'MyriadPro', textShadow: '1px 1px 2px #acb496' }); 


/*================================================
 Home
================================================*/
/*---- 2011 Winners ---*/
$('div#main.stuck-at-prom div#promotion-content.home div#winners div#image').cycle({
	fx: 'none',
	timeout: 0,
	pager: '#winners-nav',	
	pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#winners-nav li:eq(' + idx + ') a'; 
    }     
});

/*---- 2011 Finalists ----
$('#carousel').randomize('img');
$('#carousel').before('<ul id="carousel-nav" />').cycle({ 
    fx:     'fade', 
    timeout: 7000, 
    pager:  '#carousel-nav',
     
    // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) {
   		var slideThumb = $(slide).attr('src').replace('.jpg', '-thumb.jpg'); 	    
    	return '<li><a href="#"><img src="' + slideThumb + '" width="46" height="36" /></a></li>'; 
    } 
});
*/

/*---- SAP 2k12 Coundtown ----*/
var SAP2k12 = new Date(); 
//SAP2k12 = new Date(2012, 3 - 1, 7);  //Midnight
SAP2k12 = new Date(2012, 3 - 1, 7, 12,0, 0, 0); //Noon


$('#countdown').countdown({
	//until: $.countdown.UTCDate(-5, SAP2k12), 
	until: SAP2k12, 
	format: 'DHMS',
	layout: $('#countdown').html()
});


/*================================================
 Equal Columns
================================================*/
var navHeight = $('#main.stuck-at-prom #promotion-nav').height();
var contentHeight = $('#main.stuck-at-prom #promotion-content').height();

//alert('Nav Height = ' + navHeight + '\n Content Height = ' + contentHeight);

/*
if (navHeight < contentHeight) {
	if ($.browser.mozilla) {
    	//alert('FireFox');
	} 
	$('#main.stuck-at-prom #promotion-nav .callout.media-inquiries .inner').css({'padding-bottom' : (contentHeight-navHeight + 22)});
	
}else {
	$('#main.stuck-at-prom #promotion-content .inner').css({'padding-bottom' : (navHeight - contentHeight + 22)});
}
*/



/*================================================
 FAQ Smooth Scroll
================================================*/
/*
$('#promotion-content.faq ul#faq-links li').removeClass('last');
$('#promotion-content.faq ul#faq-links li').removeClass('first');

$('#promotion-content.faq ul#faq-links li').live('click', function() {
	var faqNum = '#' + $(this).attr('class');
	$('html, body').animate({scrollTop:$(faqNum).offset().top}, 2000);		
});


$('#promotion-content.faq .question span.back-to-top').live('click', function() {
	$('html, body').animate({scrollTop:$('#promotion-content').offset().top}, 2000);
});
*/


/*================================================
 Color Palette
================================================*/
$('#promotion-content.palette div.section > div.palette-item:nth-child(4n+5)').css({'margin-right' : '0px'});


/*================================================
 Gallery
================================================*/
/*---- Clear out Last Item Margin ----*/
$('#promotion-content.gallery #gallery .gallery-item:nth-child(4n)').addClass('last');

//var max_size = 200;

/*
$('#promotion-content.gallery #gallery .gallery-item img').each(function(i) {
	if ($(this).height() > $(this).width()) {
		var h = 174;
    	var w = Math.ceil($(this).width() / $(this).height() * 174);
  	} else {
    	var w = 144;
   		var h = Math.ceil($(this).height() / $(this).width() * 144);
  	}
 	
	$(this).css({'height' : h, 'width' : w });

});
*/


// End jQuery
});


/*================================================
 jQuery Randomize
================================================*/
(function($) {

$.fn.randomize = function(childElem) {
  return this.each(function() {
      var $this = $(this);
      var elems = $this.children(childElem);

      elems.sort(function() { return (Math.round(Math.random())-0.5); });  

      $this.remove(childElem);  

      for(var i=0; i < elems.length; i++)
        $this.append(elems[i]);      

  });    
}
})(jQuery);

