/*
Title:		Javascript for web site
Author:		phamp1973@gmail.com
Date:		1/1/2011
*/



/* ----------------// START SITE KEEP //------------------- */


// Side navigation load contents
$(function(){		
	$('#navigation').find('a').live('click', function(){
		$(this).loadContents();
		return false;	
	});	
});

// Footer navigation load contents
$(function(){
	$('#footer').find('a').live('click', function(){
		$(this).loadContents();
		return false;
	});	
});


// Photography load contents
$(function(){
	$('#photoNav').find('a').live('click', function(){
		$(this).loadContents();
		return false;
	});	
}); 


// Load contents
$.fn.loadContents = function() {
		
	var file = $(this).attr('href');
						
	//$('.spinner').show();
	$.ajax({
	url: file,
	dataType: 'html',
	cache: false,
	success: function() {
		$('section').load(file + ' #contents', function(){
			if(file == 'photography.html' || 'denver_zoo.html' || 'butterfly_pavilion.html' || 'fall_colors08.html' || 'insects_flowers.html' || 'pet_dogs.html' || 'artwork.html' || 'portfolio.html') {
				$.getScript('js/jquery.lightbox-0.5.min.js', function(){
					$('ul.gallery a').lightBox({});
				});					
			}		
		});			
	},
	complete: function() {
		//$('.spinner').hide(); //hide the spinner
		//alert(typeof this);	        
		}
	
	});
}


/*--- Navigation animation hover ---*/
/*$(document).ready(function(){
	$('#navigation li').hover(function(){
		$(this).find('a').addClass('hover, rounded_corners').stop()
			.animate({
				padding: '12px'
			}, 200, 'swing');
				
		}, function(){
		$(this).find('a').removeClass('hover, rounded_cornerss').stop()
			.animate({
				padding: '0'			
			}, 400, 'swing');		
	}); 	
});*/


/*-- Open External link to different window --*/
$(function(){
	$('a[href^=http://]').live('click', function(){
		$(this).attr('target', '_blank');
	});		
});



/*-- Links Page animate the link --*/
$(function(){
	$('div.links').find('a').live('mouseover mouseout', function(event){
		
		if(event.type == 'mouseover') {
			$(this).stop().animate({paddingLeft: 8}, 200, 'swing').css({backgroundColor: '#f3f0e9', opecity: .3});
		} else {
			$(this).stop().animate({paddingLeft: 0}, 300, 'swing').css({backgroundColor: ''});
		}
							
	});
});


// alter front page gallery background color
$(function(){
	$('.website').find('li:even').addClass('alterBgColor');
});


//Logo highlight/shadow plugin
(function($) {
	$.fn.emboss = function(options) {
	
		var defaults = {
			highlight: 'text_highlight',
			shadow: 'text_shadow'	
		}; // end defaults
		
		var options = $.extend(defaults, options);
		
		return this.each(function() {
			var o = options;
			var obj = $(this);
			var item = $('span', obj);
			
			item.mouseover(function() {
				obj.removeClass(o.shadow).addClass(o.highlight);				
			}).mouseout(function(){
				obj.removeClass(o.highlight).addClass(o.shadow);
			});
			
		}); // end each
			
	}; // end emboss function
	
})(jQuery);

// call emboss plugin
$(document).ready(function(){
	$('#logo').emboss({
		//shadow: 'text_highlight'
	});	
}); 


/*--- images to animate navigation ---*/
$(function(){

	// loop through each image links
	$('#navigation').find('a').each(function(){
		//var $this = $(this);
		//var source = $this.attr('src');
		//var formattedSource = source.replace('-small', '');

		$(this).hover(
			function(){
				$(this)
					//.attr('src', formattedSource)
					.stop()
					.animate({'fontSize': '17'}, 200, 'swing');
					//.animate({'width': '48', 'height': '48'}, 200, 'swing');
					//alert(source);	
			}, function(){
				$(this)
					//.attr('src', formattedSource)
					.stop()
					.animate({'fontSize': '13'}, 200, 'swing');
					//.animate({'width': '24', 'height': '24'}, 300, 'swing')	
			}
		);
	
	});
});


/*--- Plugin to animate navigation ---*/
(function($){
	$.fn.extend({
		animateMenu: function(options){
			
			var defaults = {
				animatePadding: 20,
				defaultPadding: 10,
				evenColor: '#ccc',
				oddColor: '#fff',
				bgColorHover: '#d7de9b',
				bgColorOut: 'none',
				speed: 200
			};
			
			var options = $.extend(defaults, options);
			
			return this.each(function(){
				var o = options;
				
				//Assign current element to variable
				var obj = $(this);
				
				//Get all A in the UL
				var items = $('a', obj);
				
				//Attach mouseover and mouseout event to the LI
				items.mouseover(function(){
					$(this).animate({paddingLeft: o.animatePadding}, o.speed)
						//Change link background color on mouseover
						.css('background', o.bgColorHover);	
				}).mouseout(function(){
					$(this).animate({paddingLeft: o.defaultPadding}, o.speed)
						//Change link background color on mouseout
						.css('background', o.bgColorOut);
				});
				
			}); // end each			
		} // end animateMenu
	}); // end changeLink	
})(jQuery);

// Call animate plugin for the side nav
$(document).ready(function(){
	$('#footer').animateMenu({
		animatePadding: 0, 
		defaultPadding: 0, 
		speed: 100,
		bgColorHover: 'none'
	});	
});



/*--- Flickr latest photos ---*/
$(document).ready(function(){
	$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=22186192@N08&format=json&jsoncallback=?", displayImg);
	
	function displayImg(data){
		var htmlString = '';
		
		$.each(data.items, function(i, item){
			var sourceImg = (item.media.m).replace('_m.jpg', '_s.jpg');
			if (i == 9) return false;
			
			htmlString += '<li><a href="' + item.link + '" target="_blank">';
			htmlString += '<img title="' + item.title + '" src="' + sourceImg;
			htmlString += '" alt="'; 
			htmlString += item.title + '" />';
			htmlString += '</a></li>';		
			
			$('#flickr ul').html(htmlString);
			
		});
	}		
});


/* ----------------// END SITE KEEP //-------------------*/




// Testing for form validation
$(function(){
	$('#fdform').validate({
		rules: 	{
				name: {
					required: true
					//minlength: 3
				},

				email: 	{
					required: true,
					email: true
				},
				
				comment: {
					required: true,
					minlength: 1
				}		

		}
		
		/*message: {
			name: {
				//required: "Please enter a username",
				//minlength: "Your username must consist of at least 1 characters"
			}

		}*/
		
		
	});	
});








// change class function
$.fn.changeClass = function(class1, class2){
	
	return this.each(function(){
		// this is the DOM oject
		var $element = $(this);
		
		if($element.hasClass('class1')) {
			$element.removeClass('class1').addClass('class2')
		} else if ($element.hasClass('class2')) {
			$element.removeClass('class2').addClass('class1');
		}
	});			
};

$(function(){
	$('ul.test').mouseover(function(){
		$('li').changeClass('that', 'this')
			.animate({'fontWeight': 'bold'});
		return false;
	});
});


/*
// image gallery basic test...
var GALLERY = {
	container: '#gallery',
	url: 'getImages',
	delay: 5000,
	cache: false,
	load: function() {
		// load our data
		var _gallery = this;
		
		$.ajax({
			type: 'get',
			url: this.url,
			success: function(data) {
				var images = data.split('|');
				$.each(images, function(){
					_gallery.display(this); //this is image object
				});
			}	
		});	
	},
	
	display: function(img_url) {
		// process the data
		$('<img></img>')
			.attr('src', 'images/photos/flowers_insects/' + img_url)
			.hide()
			.load(function(){
				$(this).fadeIn('slow');
			})
			.appendTo(this.container);	
	}
};

// call images
$(function(){
	GALLERY.load();	
});
*/


/*
// image gallery test...
var GALLERY = {
	container: '#gallery',
	url: 'getImages',
	delay: 5000,
	
	load: function() {
		var _gallery = this;
		
		$.ajax({
			type: 'get',
			url: this.url,
			cache: false,
			beforeSend: function(){
				$(_gallery.container)
					.find('img')
					.fadeOut('slow', function(){
						$(this).remove();	
				});
				$('<div></div>')
					.attr('id', 'spinner')
					.hide()
					.appendTo(_gallery.container)
					.fadeTo('slow', 0.6);
			},
					
			success: function(data) {
				var images = data.split('|');
				$.each(images, function(){
					_gallery.display(this);
				});	
			},
			
			complete: function(){
				setTimeout(function(){
					_gallery.load();
				}, _gallery.delay);	
				// remove spinner
				$('#spinner').fadeOut('slow', function(){
					$(this).remove();	
				});
			},
		});
	},		

	display: function(data) {
		$('<img>')
			.attr('src', 'images/photos/flowers_insects/' + data)
			.hide()
			.load(function(){
				$(this).fadeIn();
			})
			.appendTo(this.container);
	}	
}


// call images
$(function(){
	GALLERY.load();	
});
*/

/*
// test function...
$.fn.slideFadeIn = function(speed, cb) {
	return this.animate({
		height: 'show',
		opacity: 'show'		
	}, speed, cb);
};

$.fn.slideFadeOut = function(speed, cb) {
	return this.animate({
		height: 'hide',
		opacity: 'hide'	
	}, speed, cb);
};


$.fn.slideFadeToggle = function(speed, cb) {
	return this.animate({
		height: 'toggle',
		opacity: 'toggle'
	}, speed, cb);
};



$(function(){
	$('#in').click(function(){			
		$('ul.imgTest a').slideFadeIn('slow');
		return false;
	});
});

$(function(){
	$('#out').click(function(){			
		$('ul.imgTest a').slideFadeOut('slow', function(){
			var $this = $(this);
			var widths = $this.width();
			var heights = $this.height();
			$('H ' + heights + ' W: ' + widths).appendTo('#test');
			console.log(heights);
			//alert('hi');
		});
		return false;
	});
});
*/


/*
<!--div id="test"></div>
			
			
			<div id="total">hi</div>
			
			<p>Say what? <input id="sayThis" size="40"></p>
			<p>How Many times? <select id="howMany">
									<option value=1>1</option>
                            		<option value=5 selected>5</option>
                            		<option value=10>10</option>
                           			 <option value=20>20</option>
								</select></p>
		
			<p><button onclick="doLoop(fade('results'))">Do It!</button>
				<button id="reset" type="reset">Reset</button></p>
			<p><div id="results"></div></p>
			
			<button id="in" value="In">In</button>
			<button id="out" value="Out">Out</button>
			
			<script type="text/javascript">
			function doLoop() {
				var sayWhat = document.getElementById('sayThis').value;
				var maxLoop = document.getElementById('howMany').value;
				var str = '' // temp output cache it
				
				for (i=1; i <= maxLoop; i++) {
					str = str + i + ':' + sayWhat + '<br>';
				}
				document.getElementById('results').innerHTML = str;
				
			}	
			
			function colorize() {
				var element = document.getElementById('results');
				element.style.backgroundColor = '#fabb6a';
				element.style.fontWeight = 'bold';
			}
			
			colorize();
			
			
			function fade(id) {
				var dom = document.getElementById(id);
				level = 1;
				function step() {
					var h = level.toString(16);
					var str = '';
					
					dom.style.backgroundColor = '#FFFF' + h + h;
					if (level < 15) {
						level += 1;
						setTimeout(step, 300);
					}
					//document.write(str).innerHTML('section');
				}
				setTimeout(step, 300);
			}
			
			
			function sum() {
				//var i;
				n = arguments.length;
				total = 0;
				
				for(i = 0; i < n; i++) {
					total += arguments[i];
					//document.write(n).innerHTML('sum');
				}
				
				return total;
			}
			
			sum(5,5,5,6);
			//alert(total);
*/
			

/*
// aside plugin
(function($){
	$.fn.myInfo = function(options) {
		
		var defaults = {
			mBottom: 'margin-bottom',
			paddingLeft: '8',
			marginBottom: '8'			 		
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function(){
			var obj = $(this);
			var o = options;
			var item = $('p:nth-child(1n+1)', obj);
			
			item.mouseover(function(){
				$(this).css({
					marginBottom : o.marginBottom,
					paddingLeft : o.paddingLeft
				});
				
			});
			var interval = window.setInterval(function(){
				var rdcolor = Math.floor(Math.random()*257);
				$('#placeholder').empty().append(rdcolor + ' ' + rdcolor + ' ' + rdcolor + ' ');
				//alert(rdcolor);
				item.eq(3).css({color: 'rgb('+ rdcolor + ',' + rdcolor + ',' + rdcolor + ')'});
				
				
				var num = new Array('red', 'green', 'blue');
				num.push('black', 'white');
				num.pop();
				var array_length = num.length;
				var htmlString = '';
				
				for (var i = 0; i < array_length; i++) {
					var rd_number = Math.floor(Math.random()*3);
					
					htmlString += 'My random color: ' + (i+1) + ' ' + num[rd_number] + '<br />';
					
					$('#placeholder').html(htmlString)
					
				}
				
				$('#placeholder3').html('Total: ' + array_length);
				
														
				
				
				// random number
				var num = new Array('10', '20', '30', '40', '50');
				num.unshift('3', '5', '8'); // add at beginning
				num.sort();
				//num.shift();  // remove first item
				//num.push('100'); // add and at end
				//num.pop(); // remove end
				var array_length = num.length;
				var count = 0;
				var msg = '';
				
				$('#placeholder3').empty();
				
				for(var i = 0; i < array_length; i++) {
					//console.log(num[i] + '<br />');
					count++;
					
					var random = Math.floor(array_length*Math.random());
					$('#placeholder3').append('Count: ' + count + ' - ' + num[random].toString() + ' <br>');
				}
				
				// look for em and wrap in <p> if not already
				$('em, strong')
					.filter(function(){
						return !$(this).parent('p').length == 1})
							.wrap('<p></p>');
							
				// look for footer em test
				$('footer').filter(function(){
					return !$(this).parent('h1').length == 1
				}).wrap('<h1></h1>');			
				
					   
			}, 2000);			
				
		});
	}		
})(jQuery);


// call aside margin bottom plugin
$(document).ready(function(){
	$('aside').myInfo({
		paddingLeft: 10,
		marginBottom: 6
	
	});	
});
*/


/*
// count plugin
(function($){
	$.fn.count = function(customOptions) {
		// create options, extend defaultOptios and customOptions
		var options = $.extend({}, $.fn.count.defaultOptions, customOptions);
		// Return the jQuery object, or "this" after each()
		return this.each(function(){
			
			var $this = $(this);
			$this.text('0');
			// Sets the counter start number to the default option value
			// or to custom option value if it is passed to the plugin	
			$this.text(options.startCount + '');
			var Interval = window.setInterval(function(){
				var currentCount = parseFloat($this.text());
				var newCount = currentCount+1;
				$this.text(newCount+'');				
			}, 2000);
			
			//alert(this);
			//alert(this[0]);
			//alert($this[0].id);
		});
	};
	
	$.fn.count.defaultOptions = {
		startCount: 100 
	}
		
})(jQuery);

// overwrite default options
$.fn.count.defaultOptions.startCount = 200;
// count plugin call
$(document).ready(function(){
	$('#placeholder1').count();
	//$('#placeholder').count({startCount: 500});
});
*/



/*
// Demo changeDiv plugin
(function($){
	$.fn.changeDiv = function(options) {
		
		var defaults = {
			color: '#333',
			background: '#dae4ec',
			border: '1px solid #333',
			width: 500,
			height: 200
			//border: '1px solid #000'
		};
		
		var options = $.extend(defaults, options);
			
		return this.each(function(){
			var o = options;
			var obj = $(this);
			var items = $('p', obj);
			
			items.mouseover(function(){
				$(this).css({width: o.width, height: o.height, background: o.background, border: o.border})
					.fadeTo('slow', 0.7);	
			});
		});		
	}	
})(jQuery);

// call demo changeDiv plugin
$(document).ready(function(){
	//$('article').changeDiv({
		//height: 122,
		//width: 500,
		//background: '#dae4ec',
		//border: '2px dotted #666'
	//});	
});
*/



/*
// Side Navigation Plugin test...
(function($){
	$.fn.animateDock = function(options) {
		
		var defaults = {
			paddingOver: '10px',
			paddingOut: 0
		};
		
		var options = $.extend(defaults, options);
		
		//return this.each(function(){
			var o = options;
			var $this = $(this);
			//var $item = $('li', $this);
			//alert('hi');
			$this.hover(function(){
				$(this).find('a').addClass('hover, rounded_corners').stop()
					.animate({
						padding: o.paddingOver						
					}, 200, 'swing');
					
				}, function(){
				$(this).find('a').removeClass('hover, rounded_corners').stop()	
					.animate({
						padding: o.paddingOut	
 					}, 400, 'swing');					
			});
					
		//});  // end each
						
	} // end fn
	
})(jQuery); // end jquery

// Call side Navigation Plugin
$(document).ready(function(){
	$('#navigation').animateDock({
		paddingOver: 15,
		paddingOut: 0
	});	
});
*/

/*
$(document).ready(function(){
	$(document).mousemove(function(e){
		//var relativeX = e.pageX - this.offsetLeft;
		//var relativeY = e.pageY - this.offsetTop;
		$('#placeholder4').html('PageX: ' + e.pageX + ' PageY: ' + e.pageY);			
	});		
});
*/


/*
// Shadow fn test...
(function($){

	$.fn.shadow = function(options){
		
		var defaults = {
			opacity: 0.5,
			opacityNormal: 1
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function() {
			var $this = $(this);  // original element
			
			$this.css({opacity: options.opacity});	// set opacity to .55
			
			
			$this.hover(function(){
				$this.css({opacity: options.opacityNormal});	
			}, function(){
				$this.css({opacity: options.opacity});
			});
			
		}); // end each
				
	} // end shadow fn
	
})(jQuery);

// Shadow fn call...
$(document).ready(function(){
	$('img').shadow({
		opacity: 0.59
	});
});
*/


/*
// alterColor fn testting...
(function($){
	
	$.fn.alterColor = function(options) {
			
		var defaults = {
			bgColor: '#fff',
			oddRow: 'li:odd',
			evenRow: 'li:even'
		};
	
		
		var options = $.extend(defaults, options);
		
		return this.each(function(){
			var $this = $(this);
			
			$this.find(options.evenRow).css({background: options.bgColor}).addClass('rounded_corners');
				
		});		
	}	
})(jQuery);

// call altrColor fn
$(function(){
	$('ul.website').alterColor({
		bgColor: '#f1eee4'
	});	
});
*/


/*
function totals() {
	n = arguments.length;
	var total = 0;
	htmlString = '';
		
	for (i = 0; i < n; i++) {
		total += arguments[i];					
	}
		
	htmlString += ('Argument: ' + i + ' Total: ' + total);		
	$('#total').html(htmlString);
		
	return total;			
}


$(document).ready(function(){
	totals(5,5,1,4);
	//alert(total);	
});
*/


/*
// changeText plugin
(function($) {
	$.fn.changeText	= function(customOptions) {
		var options = $.extend({}, $.fn.changeText.defaultOptions, customOptions);
		
		return this.each(function() {
			var $this = $(this);
			//console.log($this);
			$this.text($this.text().replace('best', options.text));
		}); // end each	
				
	} // end changeText
	//$.fn.changeText.defaultOptions = {text: 'Hi...'};
})(jQuery); // end closure


// call changeText plugin
$(document).ready(function(){
	$('#intro').changeText({
		text: ' ...worst... :-) '
	});
});
*/


/*
$(document).ready(function(){
	var person = {
		name : 'John Doe',
		age : 33,
		wrapper : '#placeholder',
		container : '#navigation',
		myInfo : function() {
			$(this.wrapper).wrap('<em></em>').append('My name is ' + this.name + ' my age is ' + this.age);
			$(this.container)
				.children()
				//	.eq(5)
						.clone().appendTo(this.wrapper);
						
						
			$(this.container).find('a').each(function(index, obj){
				var $this = $(this);
				//alert($this);
				var titles = $this.attr('title');
				if (titles != null)
					$this.append('<em>' + titles + '</em>');
						
			});
			
		}	
	}
	
	person.myInfo({age: 44});	
});

$(document).ready(function(){
	$('#navigation')
		.find('a')
			.each(function(){
				var $this = $(this);
				var title = $this.attr('title');
				if (title !=null)
					$this.prepend('<h2>' + title + '</h2>');
					
			});		
});

$(document).ready(function(){
	$('p:first').contents().wrapAll('<h2></h2>');
	var folder = $('#navigation');
	folder
		.find('a')
		.each(function(index, links){
			var $this = $(links);
			$this.attr('href', '/' + $this.text().toLowerCase());
			
	});	
});

(function($){  
	
	$.fn.myPlugin = function() {
		//alert('jQuery version ' + this.jquery);
		return this.each(function(){
		//	alert('Current element ' + this.tagName);	
		});
	}
	
})(jQuery);
*/

$(document).ready(function(){
	//$('#clicker').myPlugin();	
	/*
	$.get('myUrl', function() {
	 // 'this' is the AJAX settings object used by the get call
	 alert(this.url == 'myUrl');
	});
	$.ajax({
	 type:   'POST',
	 url: 'myUrl',
	 timeout: 5000,
	 beforeSend:  function() {
	  alert(this.url == 'myUrl');
	 },
	 error: function() {
	  alert(this.timeout == 5000);
	 },
	 success:  function() {
	  alert(this.type == 'POST');
	 },
	 complete:  function() {
	  alert(this.async == true);
	 }
	});
	*/	
});






/*
$(document).ready(function(){
	var ele = $('p');
	
	ele.each(function(index, obj_para){
		var $this = $(this);
		
		$this.click(function(e){
			alert('This para ' + (index + 1) + ' out of ' + ele.length);
					
		e.preventDefault();		
		});
	});	
});
*/

/*
var fdHover = {
	config : {
		wrapper : '#navigation',
		on : 'red',
		off : 'green',
		handlerOut : 'mouseout',
		handlerIn : 'mouseover'
	},
	
	init : function(config) {
		$.extend(fdHover.config, config);
		$(fdHover.config.wrapper).find('a').
			hover(function(){
				fdHover.hoverOn($(this));
				return(false);
			});	
	},
	
	hoverOn : function($a) {
		$a.mouseover().addClass('zebra');
		//$a.hoverOff();	
	},
	
	hoverOff : function($a) {
		$a.mouseout().removeClass('zebra');
	}
	
	
}

$(document).ready(function(){
	fdHover.init();
});
*/

/*
var tog = {
	config : {
		wrapper : '#navigation',
		container : '#placeholder',
		border_bottom : '1px solid #ccc',
		base_url : ''	
	},
	
	init : function(config) {
		$.extend(tog.config, config);
		$(tog.config.wrapper).find('a').
			hover(function(e){
				tog.showBorder($(this));
				
			return(false);		
			});
	},
	
	buildUrl : function($a) {
		return tog.config.base_url + $a.attr('href');
	},
	
	showBorder : function($a) {
		var url = tog.buildUrl($a);
		console.log(url);
		$(tog.config.container).load(url);
				
	}
}



$(document).ready(function(){
	tog.init({border_bottom: '#000'});	
});

*/

/*
$(document).ready(function(){
	$('#placeholder').delegate('p', 'click', function(e){
		$(this).slideToggle('slow');
		
	});	
});
*/

/*
// Testing...object literal setupz
var fd = {
	config : {
		wrapper : '#navigation',
		container : '#placeholder',
		url_base : '',
		logo_blue : '#376e86'	
	}, // end config
	
	init : function(config) {
		$.extend(fd.config, config);
		$(fd.config.wrapper).find('a').
			click(function(e){
				fd.showContent($(this));
				return(false);	
			});
					
	}, // end init
	
	
	buildUrl : function($a) {
		return fd.config.url_base + $a.attr('href');
	},  // end buildUrl
	
	getContent : function($a) {
		//var url = fd.buildUrl($a);
		//$(fd.config.container).load(url);
		//console.log($(fd.config.container));
	}, // end getContent
	
	showContent : function($a) {
		var url = fd.buildUrl($a);
		//$(fd.config.container).slideDown('slow');
		$(fd.config.container).load(url);
		//$(fd.hideContent).slideUp('slow');		
	},  // end showContent
	
	hideContent : function($element) {
		//$elements.find(fd.config.container);
	}  // end hideContent
	
} // end encupsulation

$(document).ready(function(){
	fd.init({logo_blue: '#fff'});	
});
*/




