jQuery(function($) {
	if ($('#featured_media_type_id').val() == 2) {
		var flashvars = {
			'file' : Site.config.base_url + 'images/gallery/videos/' + $('#featured_media_filename').val(),
			'skin' : Site.config.base_url + 'mediaplayer/overlay.swf',
			'controlbar' : 'over',
			'image' : Site.config.base_url + 'images/gallery/videos/preview/' + $('#featured_media_preview').val()
		};
		var params = {
			allowfullscreen: 'true',
			allowscriptaccess: 'always',
			wmode : 'transparent'
		};
		var attributes = {
		};

		swfobject.embedSWF(Site.config.base_url + 'mediaplayer/player.swf','media_view_flash','319','240','9',"expressInstall.swf", flashvars, params, attributes);
	}
	
	if ($('#video_carousel a').length > 3) {
		$('#video_carousel').jCarouselLite({
	        btnNext: "#video_carousel_right",
	        btnPrev: "#video_carousel_left",
			visible: 4,
			scroll: 1
	    });
	}
	if ($('#photo_carousel a').length > 3) {
		$('#photo_carousel').jCarouselLite({
	        btnNext: "#photo_carousel_right",
	        btnPrev: "#photo_carousel_left",
			visible: 4,
			scroll: 1
	    });
	}

	$('#galleries img.video_thumb').click(function() {
		$this = $(this);
		$('#galleries img.video_thumb').removeClass('active');
		$this.addClass('active');
		var filename = $this.attr('rel');
		var preview = $this.attr('alt');
		var id = $this.attr('id').split('_').pop();
		//Send request to get file info and comments
		$('#media_container').load(Site.config.site_url + 'media_ajax/request/' + id, function() {
			var flashvars = {
				'file' : Site.config.base_url + 'images/gallery/videos/' + filename,
				'skin' : Site.config.base_url + 'mediaplayer/overlay.swf',
				'controlbar' : 'over',
				'image' : Site.config.base_url + 'images/gallery/videos/preview/' + preview
			};
			var params = {
				allowfullscreen: 'true',
				allowscriptaccess: 'always',
				wmode : 'transparent'
			};
			var attributes = {
			};

			swfobject.embedSWF(Site.config.base_url + 'mediaplayer/player.swf','media_view_flash','321','241','9',"expressInstall.swf", flashvars, params, attributes);

			
		});

	});
	

	var zoom_img_params = {
			'zoomOpacity'			: true,
			'overlayShow'			: true,
			'zoomSpeedIn'			: 500,
			'zoomSpeedOut'			: 500,
			'padding'				: 0,
			'overlayOpacity'		: .7
	};



	$('#galleries img.photo_thumb').click(function() {
		$this = $(this);
		$('#galleries img.photo_thumb').removeClass('active');
		$this.addClass('active');
		var filename = $this.attr('rel');
		var preview = $this.attr('alt');
		var id = $this.attr('id').split('_').pop();

		//Send request to get file info and comments
		$('#media_container').load(Site.config.site_url + 'media_ajax/request/' + id, function() {
			$("a#photo_orig").fancybox(zoom_img_params);
			$("a#img_large").click( function(e) {
				e.preventDefault();
				$("a#photo_orig").click();
			});
		});

	});
	
	$("a#photo_orig").fancybox(zoom_img_params);
	$("a#img_large").click( function(e) {
		e.preventDefault();
		$("a#photo_orig").click();
	});
	
	var search_value = 'Search Media';
	$('#search_media').focus(function() {
		if ($(this).val() == search_value) $(this).val('');
	}).blur(function() {
		if ($(this).val() == '') $(this).val(search_value);
	});

	
	// parse uri and on #segment0/segment1 fire click event on element id = segement0_segement1
	var segments = window.location.href.split('#').pop().split('/');
	if (segments.length == 2) {
		var id = '#' + segments[0] + '_' + segments[1];
		if ($(id).length) {
			$(id).click();
		}
	}
});