/*
Christmas For Kids global javascript
*/

//Homepage Masthead Slider
$(document).ready(function(){
	
	//Cufon text replacement
	Cufon.replace('#header li');
	Cufon.replace('#ribbon h2');
	Cufon.replace('.title');
	Cufon.replace('.comments h1');
	
	//Homepage Masthead Image Slider
	function buildPager(idx, slide) {
    	return '<li><a href="#">' +  $(slide).attr('title') + '</a></li>';
	}
	
	// insert pager container markup
	$('#featured').append('<div id="featureNav"><ol></ol></div>');

	//Home slider 
	$('#featured .items').cycle({
		fx: 'fade',
		timeout: 5000, //Slide duration in miliseconds
		pager:   '#featureNav ol',
		activePagerClass: 'on',
		pagerAnchorBuilder: buildPager,
		pause: true,
		pauseOnPagerHover: true
	});
	
});

$(document).ready(function() {
	//Search box 
	window.onload = function() {
	  applyDefaultValue(document.getElementById('s'), 'Search');
	}
	
	function applyDefaultValue(elem, val) {
	  elem.style.color = '#525252';
	  elem.value = val;
	  elem.onfocus = function() {
		if(this.value == val) {
		  this.style.color = '';
		  this.value = '';
		}
	  }
	  elem.onblur = function() {
		if(this.value == '') {
		  this.style.color = '#525252';
		  this.value = val;
		}
	  }
	};
	
});

//On Focus commands for comment fields
$(document).ready(function() {
   $('input[type="text"]').addClass("idleField");
	$('input[type="text"]').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
        if (this.value == this.defaultValue){
        	this.value = '';
    	}
        if(this.value != this.defaultValue){
	    	this.select();
        }
    });
    $('input[type="text"]').blur(function() {
    	$(this).removeClass("focusField").addClass("idleField");
        if ($.trim(this.value == '')){
        	this.value = (this.defaultValue ? this.defaultValue : '');
    	}
    });
	$('textarea').addClass("idleField");
	$('textarea').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
        if (this.value == this.defaultValue){
        	this.value = '';
    	}
        if(this.value != this.defaultValue){
	    	this.select();
        }
    });
    $('textarea').blur(function() {
    	$(this).removeClass("focusField").addClass("idleField");
        if ($.trim(this.value == '')){
        	this.value = (this.defaultValue ? this.defaultValue : '');
    	}
    });
});


