var mgroup = {

	init: function() {
		this.prepareDocument();
		this.enableFancybox();
		this.enableFancyplayer(); 
		this.enableCarousel();
	},

	enableCarousel: function() {	
		jQuery('.slide-carousel') 
			.after('<div id="control">') 
			.cycle({ 
				fx:     'scrollHorz', 
				speed:   1000, 
				timeout: 4000,
				pager:  '#control',
				pause:	1
		});
		jQuery('.fade-carousel') 
			.cycle({ 
				fx:     'fade', 
				speed:   1000, 
				timeout: 4000
		});
	},

	prepareDocument: function() {
		$('html').addClass('js');
		$('body:not(.home)').find("#content, #aside").equalHeights(500); 
	},
	
	enableFancyplayer: function() {
	
		var swfplayer = "http://sandbox.mxnet.info/mgroup/wp-content/themes/mgroup/video/flowplayer-3.1.1.swf";

		$(".e-video").hover(
			function(){ videoclip = this.href; this.href = '#video'; }, 
			function(){ this.href = videoclip; })
		.fancybox({
			'hideOnContentClick':false,
			'overlayOpacity' :.6,
			'zoomSpeedIn'    :400,
			'zoomSpeedOut'   :400,
			'easingIn'		 : 'easeOutBack',
			'easingOut'		 : 'easeInBack',
			'titleShow': false,
			'callbackOnShow' : function(){
					player = $f("fancy_div", swfplayer,{
					play:{opacity:0},
					clip:{
						autoPlay:true,
						autoBuffering:true,
						url: videoclip,
						onStart:function(clip){
							var wrap=jQuery(this.getParent());
							var clipwidth = clip.metaData.width;
							var clipheight= clip.metaData.height;
							var pos = $.fn.fancybox.getViewport();
							$("#fancy_outer")
								.css({ width:clipwidth, height:clipheight })
								.css('left', ((clipwidth + 36) > pos[0] ? pos[2] : pos[2] + Math.round((pos[0] - clipwidth	- 36)	/ 2)))
								.css('top',  ((clipheight + 50) > pos[1] ? pos[3] : pos[3] + Math.round((pos[1] - clipheight - 50)	/ 2)));
						}
					}
				});
				player.load();
				$('#fancy_close').click(function(){
					$("#fancy_div_api").remove();
				});
			},
			'callbackOnClose':function(){
				$("#fancy_div_api").remove();
			}
		});
	},
    
	enableFancybox: function() {
		$('body:not(.home, .services, .star-elm)').find('a:has(img)').attr('rel', 'gallery').fancybox({
			'transitionIn': 'fade',
			'transitionOut': 'fade',
			'opacity': false,
			'overlayShow': true,
			'hideOnContentClick': true,
			'titleShow': false,
			'speedIn': 200,
			'speedOut': 200,
			'padding': 7
		});
	}
};

$(function() {
	mgroup.init();
});
