/* Author: 

*/


$(function(){

	// Make about and contact equal height.
	// We could fight with CSS and Structure do do this but 
	// why bother.
	$('#about,#contact').css('height',Math.max(
		$('#about').outerHeight(),
		$('#contact').outerHeight()
	));
	
	// Check for an alert
	// http://stackoverflow.com/questions/901115/get-querystring-values-in-javascript
	var urlParams = {};
	(function () {
	    var e,
	        a = /\+/g,  // Regex for replacing addition symbol with a space
	        r = /([^&=]+)=?([^&]*)/g,
	        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
	        q = window.location.search.substring(1);
	
	    while (e = r.exec(q))
	       urlParams[d(e[1])] = d(e[2]);
	})();
	
	
	if ("status" in urlParams) {
	
		switch(urlParams.status) {
			case "sent": 
				
				$('<div id="dialog-message" title="Message Sent"><p>Thanks, your message has been sent.</p></div>')
					.dialog({
						modal: true,
						buttons: {
							Ok: function() {
								$( this ).dialog( "close" );
							}
						}
					});
					break;
		}
	}
	
	
  // Fade in the majority of the content.	
  // in the home page.
  
  /*
  $('#page-home')
    .find("header,footer,#rss,#about,#contact,#developers")
   	.css("opacity",0)
   	.animate({
   	    opacity: 1
   	  }, 2000, function() {
   	    // Animation complete.
   	  });
	*/
	
	// 234x448
	$('ul.slides').cycle();
	
    /*
	$('.video-clip').each(function(i,e){
		var e = $(e);
		var placeholder = e.find('img');
		var title = e.find('.title');
		var sources = e.find('a');
		e.empty();
		
		// Creat the video eleemnts.
		var href = $(sources[0]).attr('href');
		var prefix = href.substr(0,href.lastIndexOf('.')); 
		
		var video = $('<div>')
			.css('display','none')
			.appendTo(document.body)
			.append('<video id="clip-' + e.attr('id') + '" width="950" height="876" preload controls>')
			.append('<source src="' + prefix + '.webm" type=\'video/webm; codecs="vp8, vorbis"\' />')
			.append('<source src="' + prefix + '.ogv" type=\'video/ogg; codecs="theora, vorbis"\' />')
			.append('<source src="' + prefix + '.mp4" />')
			.append('<object width="950" height="876" type="application/x-shockwave-flash"'
			  + 'data="flowplayer-3.2.1.swf">'
			  + '<param name="movie" value="flowplayer-3.2.1.swf" />'
			  + '<param name="allowfullscreen" value="true" />'
			  + '<param name="flashvars" value=\'config={"clip": {"url": "' + prefix + '.mp4", "autoPlay":false, "autoBuffering":true}}\' />'
			  + '<p>Download video as <a href="' + prefix + '.mp4">MP4</a>, <a href="' + prefix + '.webm">WebM</a>, or <a href="' + prefix + '.ogv">Ogg</a>.</p>'
			+ '</object>');
			
		placeholder.colorbox({inline:true, href:'#clip-' + e.attr('id')});
		
		e.append(placeholder);
		$('<a/>')
			.html(title.html())
			.colorbox({inline:true, href:'#clip-' + e.attr('id')})
			.appendTo(e);
	});
    */
    
    	$('.video-clip a').each(function(i,e){
            var e = $(e);
        
            //http://www.youtube.com/watch?v=CD2LRROpph0
            //http://www.youtube.com/embed/617ANIA5Rqs?rel=0

            e.attr('href',e.attr('href').replace('watch?v=','v/') + '&fmt=22');
            e.colorbox({iframe:true, innerWidth:640, innerHeight:390});
        });

	
	
	// Assign handlers immediately after making the request,
	// and remember the jqxhr object for this request
	/*
	var jqxhr = $.getJSON("lozzal-json.php", function(d) {
	  console.log(d);
	  $('#suggestion').html('Near ' + d.location + '? ' + d.suggestion);
	})
	// perform other work here ...
	*/
		
});





















