function header_video(video, initialPic, finalPic) {
	if( typeof(video) == 'undefined' )
		return false;

	if( typeof(initialPic) == 'undefined' )
		initialPic = false;

	if( typeof(finalPic) == 'undefined' )
		finalPic = false;

	LbVideoPlace('header_swf', {
				autoplay	: true,
				initialPic	: initialPic,
				finalPic	: finalPic,
				videoFile	: video,
				wmode		: 'opaque',
				skin		: '/static/swf/lb_home_skin.swf',
				width		: 794,
				height		: 314
			})
}

function header_video_project(video, initialPic, finalPic) {
	if( typeof(video) == 'undefined' )
		return false;

	if( typeof(initialPic) == 'undefined' )
		initialPic = false;

	if( typeof(finalPic) == 'undefined' )
		finalPic = false;

	LbVideoPlace('header_project', {
				autoplay	: true,
				initialPic	: initialPic,
				finalPic	: finalPic,
				videoFile	: video,
				wmode		: 'opaque',
				width		: 556,
				height		: 316
			})
}


function video_player(div_id){
    var options = {
		// default options
		videoFile	: ( typeof(arguments[1].videoFile)	!= 'undefined' ) ? arguments[1].videoFile	: 'movie',
		title		: ( typeof(arguments[1].title)		!= 'undefined' ) ? arguments[1].title		: '',
		subtitle	: ( typeof(arguments[1].subtitle)	!= 'undefined' ) ? arguments[1].subtitle	: '',
		autoplay	: ( typeof(arguments[1].autoplay)	!= 'undefined' ) ? arguments[1].autoplay	: 'false'
	}

	LbVideoPlace(div_id, {
				autoload	: true,
				autoplay    : options.autoplay,
				videoFile	: options.videoFile,
				title		: options.title,
				subtitle	: options.subtitle,
                width		: 512,
				height		: 288,
				wmode       :'opaque'
			})
}
// written by Dean Edwards, 2005
// with input from Tino Zijdel - crisp@xs4all.nl
// http://dean.edwards.name/weblog/2005/10/add-event/
function addEvent(element, type, handler)
{
	if (element.addEventListener)
		element.addEventListener(type, handler, false);
	else
	{
		if (!handler.$$guid) handler.$$guid = addEvent.guid++;
		if (!element.events) element.events = {};
		var handlers = element.events[type];
		if (!handlers)
		{
			handlers = element.events[type] = {};
			if (element['on' + type]) handlers[0] = element['on' + type];
			element['on' + type] = handleEvent;
		}
	
		handlers[handler.$$guid] = handler;
	}
}

addEvent.guid = 1;

function removeEvent(element, type, handler)
{
	if (element.removeEventListener)
		element.removeEventListener(type, handler, false);
	else if (element.events && element.events[type] && handler.$$guid)
		delete element.events[type][handler.$$guid];
}

function handleEvent(event)
{
	event = event || fixEvent(window.event);
	var returnValue = true;
	var handlers = this.events[event.type];

	for (var i in handlers)
	{
		if (!Object.prototype[i])
		{
			this.$$handler = handlers[i];
			if (this.$$handler(event) === false) returnValue = false;
		}
	}

	if (this.$$handler) this.$$handler = null;

	return returnValue;
}

function fixEvent(event)
{
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
}
fixEvent.preventDefault = function()
{
	this.returnValue = false;
}
fixEvent.stopPropagation = function()
{
	this.cancelBubble = true;
}

// This little snippet fixes the problem that the onload attribute on the body-element will overwrite
// previous attached events on the window object for the onload event
if (!window.addEventListener)
{
	document.onreadystatechange = function()
	{
		if (window.onload && window.onload != handleEvent)
		{
			addEvent(window, 'load', window.onload);
			window.onload = handleEvent;
		}
	}
}


function is_video(extension){
	var video_types = ['mov', 'mp4', 'm4v', 'flv'];

	var types = "|" + video_types.join("|") + "|";

	return types.indexOf("|" + extension + "|");
}

$(document).ready(function(){
   
    /*
     * Modal windows
     */
     
   	$.nyroModalSettings({ closeButton 		: '<a href="#" class="nyroModalClose" id="closeBut" title="close"><img src="/static/img/close.png" alt="close" /></a>',
   						  minHeight			: 50,
   						  showContent       : showContent,
   						  hideContent       : hideContent,
   						  processHandler	: function(settings) {
								var url = settings.url;
								var formatting = url.split('.');
								var format = formatting[formatting.length-1];

								if( is_video( format ) > -1 ) {

									$.nyroModalSettings({
										type: 'swf',
										height: 288,
										width : 512,
										url: url.replace(new RegExp("watch\\?v=", "i"), 'v/')
									});
									
									
									setTimeout($.bind(function(){

                                        video_player('nyroModalContent', {videoFile   : url, title : settings.title, autoplay  : true})
						
						            }, this), 1500);

								}else if( format == 'png' || format == 'jpg' || format == 'gif' ){

						        }else if( format == 'swf' ){
									$.nyroModalSettings({
							            type: 'swf',
										width: 512,
										url: url
									});						
						        } else if ( format == 'pdf' ){
									$.nyroModalSettings({
							            type: 'iframe',
							            height	: 512,
										width: 512,
										url: url
									});						
						        }
						        	

							}
						});

	$('.modal').nyroModal();

});

function showContent(elts, settings, callback) {
    elts.contentWrapper
    .css({ // Reset the CSS at the start position
        marginTop: (-100/2 + settings.marginScrollTop)+'px',
        marginLeft: (-100/2 + settings.marginScrollLeft)+'px',
        height: '100px',
        width: '100px',
        opacity: 0
    })
    .show()
    .animate({ // Set the width
        width: settings.width+'px',
        marginLeft: (settings.marginLeft)+'px',
        opacity: 0.5
    }, {duration: 300})
    .animate({ // Set the height
        height: settings.height+'px',
        marginTop: (settings.marginTop)+'px',
        opacity: 1
    }, { complete: callback, duration: 400 });
}

function hideContent(elts, settings, callback) {
    elts.contentWrapper
    .animate({ // Set the height
        opacity: 0
    }, { complete: callback, duration: 300 });
}

function lightbox_from_swf(url) {
    $('#temp_lightbox').remove();
    $('body').append('<div id="temp_lightbox" style="display:none"><a href="' + url + '">clicky</div>');
    $('#temp_lightbox a').nyroModal();
    $('#temp_lightbox a').click();
}