(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 drawDots() {
	jQuery('#navcontainer a.current').add('#navcontainer a.currentAncestor').prepend('<div class="dot" />');
	if (window.PIE) {
        jQuery('.dot').each(function() {
            PIE.attach(this);
        });
        jQuery('.dotActive').each(function() {
            PIE.attach(this);
        });
    }
    
	jQuery('#navcontainer a.current').add('#navcontainer a.currentAncestor').hover(function() {
		jQuery(this).find('div.dot').stop(true, true).switchClass('dot', 'dotActive', 100);
	}, function() {
		jQuery(this).find('div.dotActive').stop(true, true).switchClass('dotActive', 'dot', 100);
	});
		
}

function getSitePath() {
	trimPath='rw_common/themes/ohm/javascript.js';
	sitePath=rwCommonPath.replace(trimPath, '');
	return sitePath;
}

function goHome() {
	jQuery('#logo').hover(function() {
		jQuery(this).css('cursor', 'pointer');
	}, function() {
		jQuery(this).css('cursor', 'default');
	});
	
	jQuery('#logo').click(function() {
		location.href=sitePath+'index.html';
		});
}
function addToHeader() {
	//jQuery('#pageHeader').before('<div id="importedHeader"></div>');
	if (jQuery('#content #addToHeader').length==0) {return;}
	jQuery('#pageHeader').html(jQuery('#addToHeader').html());
	jQuery('#content #addToHeader').empty();
	return;
}

function addToFooter() {
	if (jQuery('#content #addToFooter').length==0) {return;}
	jQuery('#footer').prepend('<div id="importedFooter">'+jQuery('#addToFooter').html()+'</div>');
	jQuery('#content #addToFooter').empty();
	return;
}

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


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 fixiDevSB() {
	if (iPhone || iPad) {
	jQuery('#content a').click(function(e) {
		var relTag=jQuery(this).attr('rel');
		if ((/shadowbox/gi.test(relTag)) || (/lightbox/gi.test(relTag))) {
			var wScroll=jQuery(window).scrollTop();
			wScroll-=30;
			var wScrollCSS=wScroll+'px';
			jQuery('#sb-container').css('top', wScrollCSS);
		}
	});
	}
	return;
}

jQuery(function() {
	iPhone=checkiPhone();
	iPad=checkiPad();
	drawDots();
	sitePath=getSitePath();
	goHome();
	addToHeader();
	addToFooter();
	setUpPhotoAlbumSB();
	initSB();
	fixiDevSB();
});



