jQuery(document).ready(function($) {
	$('a[rel*=lightbox]').colorbox();
	$('a#launchLightbox').click(function(){
		$('a[rel*=lightbox]:first').click();
		return false;
	});
	$('a.videoLink').each(function(){
		var myClasses = this.className.split(' ');
		for(var i=0; i<myClasses.length; i++) {
			if (myClasses[i].match(/^[wh]_\d+$/)) {
				var dim = myClasses[i].split('_');
				$(this).data('video_'+dim[0], dim[1]);
			}
		}
		$(this).data('video', this.href);
		$(this).attr('href','#');
	})
	$('a.videoLink').click(function(){
		$('body #colorbox_video_wrap').remove();
		$('body').append('<div id="colorbox_video_wrap"><div id="colorbox_video"><div id="videoplayer"></div></div></div>');

		var videoSrc = $(this).data('video');
		var videoW = $(this).data('video_w');
		var videoH = $(this).data('video_h');

		$('#videoplayer').wrap('<div style="width:'+videoW+'px;height:'+videoH+'px"/>');
		$.fn.colorbox({open:true, inline:true, href:'#colorbox_video', initialWidth:videoW, initialHeight:videoH,scrolling:false,onComplete:function(){
			var flashvars = {'video':videoSrc, 'skinFile':template_directory+'/swf/SteelOverPlaySeekVolume.swf','skinAutoHide':1};
			var params = {'swLiveConnect':'true', 'wmode':'transparent'};
			swfobject.embedSWF(template_directory+"/swf/videoplayer.swf", "videoplayer", videoW, videoH, "8.0.0", template_directory+"/swf/expressInstall.swf", flashvars, params, params);
		}});
		return false;
	})

	jQuery('.homebanners').bind('slide', function(){
		var activeEl = jQuery(this).children('.bannerLayout.active');
		if (activeEl.length == 0) activeEl = jQuery(this).children('.bannerLayout:first');
		var nextEl = activeEl.next('.bannerLayout').length ? activeEl.next('.bannerLayout') : jQuery(this).children('.bannerLayout:first');
		activeEl.addClass('last-active');
		nextEl.css({opacity: 0.0, display:'block'}).addClass('active').animate({opacity: 1.0}, 1000, function() {
			activeEl.removeClass('active last-active');
		});
	});

	if (jQuery('.homebanners .bannerLayout').length) {
		jQuery(window).load(function(){
			setInterval( "jQuery('.homebanners').trigger('slide');", 3500 );
		});
	}
});

