// Copyright 2009 Phase One Media All Rights Reserved
//
// jQuery Initialization
//////////////////////////////////////////////////////

$(document).ready(function() {

	$(function() {

		$("body").append('<div style="text-align: center;" id="aim-dialog"><iframe frameborder="0" width="200" scrolling="no" id="aim-frame"></iframe></div>');
		$("body").append('<div style="text-align: center;" id="yim-dialog"><iframe frameborder="0" width="250" scrolling="no" id="yim-frame"></iframe></div>');
		$("body").append('<div style="text-align: center;" id="msn-dialog"><iframe frameborder="0" width="300" scrolling="no" id="msn-frame"></iframe></div>');
		$("body").append('<div id="contact-dialog"><iframe frameborder="0" width="800" scrolling="no" id="contact-frame"></iframe></div>');
		$("body").append('<div id="twitter-dialog"><iframe frameborder="0" width="800" scrolling="no" id="twitter-frame"></iframe></div>');
		$("body").append('<div id="loading-dialog"><div style="width: 100%; text-align: center;"><img src="http://phaseonemedia.com/images/loading.gif" border="0" alt="" /></div><br /><div id="progressbar"></div><br /><div id="loading-text"></div></div>');


		$('#mail').click(function() { $('#contact-dialog').dialog('open'); });
		$('#aim').click(function() { $('#aim-dialog').dialog('open'); });
		$('#yim').click(function() { $('#yim-dialog').dialog('open'); });
		$('#msn').click(function() { $('#msn-dialog').dialog('open'); });
		$('#twitter').click(function() { $('#twitter-dialog').dialog('open'); });


		function updateProgress() {
			var progress;
			progress = $("#progressbar").progressbar("option","value");
			if (progress <= 100) {
				$("#progressbar").progressbar("option", "value", progress + 1);
				$('#loading-text').replaceWith('<div id="loading-text"><center><b>Loading ' + progress + '%</b></center></div>');
				setTimeout(updateProgress, 10);
			} else {
				if (location.pathname == "/services.html") {
					jQuery.each(jQuery.browser, function(i) {
						if($.browser.msie){
							//sfx('sfx-background');
						}
					});
				} else {
					//sfx('sfx-startup');
				}
				$('#loading-dialog').dialog('close');
			}
		}

		$('#loading-dialog').dialog({
			autoOpen: true,
			resizable: true,
			width: 400,
			open: function() {
				$("#progressbar").progressbar({ value: 0 });
				setTimeout(updateProgress, 10);
			},
			modal: true,
			show: 'drop',
			hide: 'drop',
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			}
		});



		$('#aim-dialog').dialog({
			autoOpen: false,
			bgiframe: true,
			resizable: true,
			position: 'top',
			width: 240,
			open: function() {
				$('#aim-frame').attr('src', 'im/aim.html');
				setTimeout("$('#aim-frame').reload();", 1500);
				$('#aim-frame').animate({ height: "310" }, 1500);
			},
			close: function(){
				$('#aim-frame').attr('src', 'blank.html');
			},
			modal: true,
			show: 'drop',
			hide: 'drop',
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			}
		});

		$('#yim-dialog').dialog({
			autoOpen: false,
			bgiframe: true,
			resizable: true,
			position: 'top',
			width: 300,
			open: function() {
				$('#yim-frame').attr('src', 'im/yahoo.html');
				$('#yim-frame').animate({ height: "450" }, 1500);
			},
			close: function(){
				$('#yim-frame').attr('src', 'blank.html');
			},
			modal: true,
			show: 'drop',
			hide: 'drop',
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			}
		});

		$('#msn-dialog').dialog({
			autoOpen: false,
			bgiframe: true,
			resizable: true,
			position: 'top',
			width: 350,
			open: function() {
				$('#msn-frame').attr('src', 'im/msn.html');
				$('#msn-frame').animate({ height: "335" }, 1500);
			},
			close: function(){
				$('#msn-frame').attr('src', 'blank.html');
			},
			modal: true,
			show: 'drop',
			hide: 'drop',
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			}
		});

		$('#twitter-dialog').dialog({
			autoOpen: false,
			bgiframe: true,
			resizable: true,
			position: 'top',
			width: 850,
			open: function() {
				$('#twitter-frame').attr('src', 'im/twitter.php');
				$('#twitter-frame').animate({ height: "300" }, 1500);
			},
			close: function(){
				$('#twitter-frame').attr('src', 'blank.html');
			},
			modal: true,
			show: 'drop',
			hide: 'drop',
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			}
		});

		$('#contact-dialog').dialog({
			autoOpen: false,
			bgiframe: true,
			resizable: true,
			position: 'top',
			width: 850,
			open: function() {
				$('#contact-frame').attr('src', 'contact.html');
				$('#contact-frame').animate({ height: "800" }, 1500);
			},
			close: function(){
				$('#contact-frame').attr('src', 'blank.html');
			},
			modal: true,
			show: 'drop',
			hide: 'drop',
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			}
		});


	});
});

jQuery(function( $ ){
	$('#service_container').serialScroll({
		target:'#sections',
		items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		//prev:'img.prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		//next:'img.next',// Selector to the 'next' button (absolute too)
		//axis:'xy',// The default is 'y' scroll on both ways
		navigation:'#navigation li',
		duration:500,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		//force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
		
		//queue:false,// We scroll on both axes, scroll both at the same time.
		//event:'click',// On which event to react (click is the default, you probably won't need to specify it)
		//stop:false,// Each click will stop any previous animations of the target. (false by default)
		//lock:true, // Ignore events if already animating (true by default)		
		//start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )		
		//cycle:true,// Cycle endlessly ( constant velocity, true is the default )
		//step:1, // How many items to scroll each time ( 1 is the default, no need to specify )
		//jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
		//lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
		//interval:1000, // It's the number of milliseconds to automatically go to the next
		//constant:true, // constant speed
		
		onBefore:function( e, elem, $pane, $items, pos ){
			/**
			 * 'this' is the triggered element 
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			 //those arguments with a $ are jqueryfied, elem isn't.
			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			//'this' is the element being scrolled ($pane) not jqueryfied
		}
	});
});
