﻿$(document).ready(function(){
	/*
	----------------------------------------------------------------------
	GET URL PARAMATER
	----------------------------------------------------------------------
	*/
	function getURLParm(name) {
		return unescape(
			(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
		);
	}
	
	//Closes modal window and modal bg, reset to black.
	$('.modal-close').click(function(e){
		e.preventDefault();
		$(this).parents('.modal-window').hide();
		$('.modal-bg').animate({
			opacity: 0
		}, 250, function(){
			$(this).hide();
		});
		
		if( $('.modal-bg').hasClass('white') )
			$('.modal-bg').removeClass('white');
	});
	
	//Shows background modal and fills window, then show modal window
	function showModal(window){
		var w = $(document).width();
		var h = $(document).height();
		var offset = $('body').offset();

		$('.modal-bg').css({
			'width' : w,
			'height' : h,
			'left': '-' + offset.left + 'px',
			'top' : '-' + offset.top + 'px',
			'display' : 'block',
			'z-index' : '20'
		}).animate({
			opacity: .8
		}, 250, function(){
			$(window).css({
				'top': '75px',
				'left': '50%',
				'margin-left': '-' + $(window).width()/2 + 'px'
			}).fadeIn('fast', function(){
				if (!$.support.opacity) 
					this.style.removeAttribute('filter');
			});
		});
	}	
	
	$('.play-seclabs-video').live('click', function(e){
		e.preventDefault();
		var videourl = $(this).attr('href');
		showModal( $('#video-player') );
		$('.modal-header p').html( $(this).attr('title') );
		
		$f("player", "/assets/swf/flowplayer-3.2.7.swf", {
			key: '#@f113ffd29f0d2a7f09c',
			clip: {
				url: videourl,
				autoPlay: true,
				autoBuffering: true,
				eventCategory: 'Security Labs Diary'
			},
			plugins:{
				gatracker: {
					url: "/assets/swf/flowplayer.analytics-3.2.2.swf",
					events: {
						all: true
					},
					accountId: "UA-23948603-1" // your Google Analytics id here
				}
			}
		});
	
	})
	
	$('#video-player a.modal-close').live('click', function(e){
		e.preventDefault();
		$f("player").stop();
	})
	
		
	$('.v-archive').click(function(e){
		e.preventDefault();
		var url = $(this).attr('href');
		var title = $(this).attr('title');
		$f("player").play(url);
		$('.modal-header p').html(title);
	});

	$('#video-list-inner ul').jcarousel({
		scroll: 4
	});

	
	if( getURLParm('external') != 'null' ){
		showModal( $('#video-player') );
		var videourl = getURLParm('external');
		$('.modal-header p').html( $('a[href='+videourl+']').attr('title'));
		$f("player", "/assets/swf/flowplayer-3.2.7.swf",{
			key: '#@f113ffd29f0d2a7f09c',
			clip: {
				url: videourl,
				autoPlay: true,
				autoBuffering: true,
				eventCategory: 'Security Labs Diary'
			},
			plugins:{
				gatracker: {
					url: "/assets/swf/flowplayer.analytics-3.2.2.swf",
					events: {
						all: true
					},
					accountId: "UA-23948603-1" // your Google Analytics id here
				}
			}
		});
	
	}	
});
