(function($) {
    $.fn.wait = function(option, options) {
        milli = 1000; 
        if (option && (typeof option == 'function' || isNaN(option)) ) { 
            options = option;
        } else if (option) { 
            milli = option;
        }
        // set defaults
        var defaults = {
            msec: milli,
            onEnd: options
        },
        settings = $.extend({},defaults, options);

        if(typeof settings.onEnd == 'function') {
            this.each(function() {
                setTimeout(settings.onEnd, settings.msec);
            });
            return this;
        } else {
            return this.queue('fx',
            function() {
                var self = this;
                setTimeout(function() { $.dequeue(self); },settings.msec);
            });
        }

    }
})(jQuery);

function checkiPhone() {
	var iPhone=((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)));
	return iPhone;
}

function checkiPad() {
	var iPad=navigator.userAgent.match(/iPad/i);
	return iPad;
}

function initSB() {
	Shadowbox.init({
		players: ["html","img","swf","flv","qt","iframe"]
	});
	return;
}

function openExtCB() {
	jQuery('div.go a').not('#yr div.go a').colorbox({
		'iframe': 'true',
		'innerWidth': '900',
		'innerHeight': '770',
		onOpen:function(){
			var theTarget=jQuery(this).attr('href');
			jQuery(theTarget).css('display', 'block');
			jQuery('a.inFrame').next().first().css({'width': 0, 'opacity': 0}).hide();
		 }
		});
	return;
}

function openExtDefaultCB() {
	jQuery('a.goExt').colorbox({
		'iframe': 'true',
		'innerWidth': '780',
		'innerHeight': '550',
		onOpen:function(){
			jQuery('a.inFrame').next().first().css({'width': 0, 'opacity': 0}).hide();
		 }
		});
	return;
}

function openIntCB() {
	jQuery('a.goInt').colorbox({
		'inline': 'true',
		'innerWidth': '780',
		'innerHeight': '550',
		onOpen:function(){
			var theTarget=jQuery(this).attr('href');
			jQuery(theTarget).css('display', 'block');
			jQuery('a.inFrame').next().first().css({'width': 0, 'opacity': 0}).hide();
		 },
		 onCleanup:function(){
			var theTarget=jQuery(this).attr('href');
			jQuery(theTarget).css('display', 'none');
		 }
	});
	return;
}

function openExt() {
	jQuery('a[rel=external]').attr('target', 'openExt');
	return;
}

function openInFrame() {
	jQuery('a.inFrame').next().first().css({
		'width': '0',
		'right': 0,
		'left': 'auto',
		'bottom': 0,
		'top': 'auto',
		'position': 'absolute',
		'height': '280px'
		});
	jQuery('a.inFrame').click(function(e) {
		jQuery(this).next().first().stop().animate({
			'width': '240px',
			'opacity': 1
		});
		e.preventDefault();
	});
	return;
}

function loadWPTags() {
	jQuery('#wpTags').load('http://www.richardet-design.com/wp/ li[id^=tag_cloud] div', function() {
		jQuery('#wpTags').find('div').prepend('<strong>Blog Tags: </strong>')});
		jQuery('#wpTags a').live('click', function(e) {
			theURL=jQuery(this).attr('href');
			jQuery.colorbox({href:theURL, 'iframe': 'true', 'innerWidth': '800', 'innerHeight': '600'});
			e.preventDefault();
		});
}

function startPage() {
	jQuery('#container').css({
		'opacity': '0',
		'display': 'block'
	});
	jQuery('#preContent').css('opacity', '0').wait(1000).animate({
		'opacity': 1},2000);
	jQuery(window).load(function() {
		jQuery('#preContent').wait(2000).animate({'opacity': 0.1, 'margin-top': '-300px'}, 1000, function() {
			jQuery('#container').animate({'opacity': 1}, 800);
			loadWPTags();
		
		});
	});
	return;
}

jQuery(function() {
	startPage();
	openExt();
	//loadWPTags();
	openExtCB();
	openExtDefaultCB();
	openIntCB();
	openInFrame();
	preProcessForm();
	
	jQuery('a#formLink').colorbox({
		'inline': 'true',
		'innerWidth': '280',
		'innerHeight': '400',
		onOpen:function(){
			var theTarget=jQuery(this).attr('href');
			jQuery(theTarget).css('display', 'block');
			jQuery('a.inFrame').next().first().css({'width': 0, 'opacity': 0}).hide();
		 },
		 onCleanup:function(){
			 jQuery('#response').hide();
			var theTarget=jQuery(this).attr('href');
			jQuery(theTarget).css('display', 'none');
		 }
	});
	
	jQuery('div#yr div.go a').colorbox({
		'iframe': 'true',
		'innerWidth': '940',
		'innerHeight': '666',
		onOpen:function(){
			var theTarget=jQuery(this).attr('href');
			jQuery(theTarget).css('display', 'block');
			jQuery('a.inFrame').next().first().css({'width': 0, 'opacity': 0}).hide();
		 },
		 onCleanup:function(){
			var theTarget=jQuery(this).attr('href');
			jQuery(theTarget).css('display', 'none');
		 }
	});
	jQuery('div.overlay a').hover(
		function() {
				jQuery(this).stop().animate({
					'color': '#ffffff'
					
				}, 400);
			}, function() {
				jQuery(this).stop().animate({
					'color': '#999999'
				}, 200);
			});
	jQuery('div.overlay div.go a').hover(
		function() {
				jQuery(this).stop().animate({
					'color': '#ffffff',
					'borderColor': '#fb0000',
					'backgroundColor': '#111111'
					
				}, 400);
			}, function() {
				jQuery(this).stop().animate({
					'color': '#999999',
					'borderColor': '#444444',
					'backgroundColor': '#222222'
				}, 200);
			});		
		
	jQuery('div.overlay').each(function() {
		jQuery(this).css({
			'width': '0',
			'right': 0,
			'left': 'auto',
		})
		.hide();});
		jQuery('div.next').hover(
			function() {
				jQuery(this).find('div.overlay').stop().animate({
					'width': '240px'
				}, 400);
			}, function() {
				jQuery(this).find('div.overlay').stop().wait(1000).animate({
					'width': 0
				}, 200);
			});
			
	return;
});
