


function _init_gallery() {
	// Number of images displayed as thumbnails
	var images_per_frame = 4;
	// Number of images in thumnail list
	var num_of_images = $('.gallery_list li').size();
	// Current location of thumbnail sprite
	var cur_thumb_pos = 1;
	
	var item_width = 164;
	var frame_width = item_width * images_per_frame;


	// INIT TABS 
	var tabContainers = $('.tab_container');
    
	$('.tabs a').click(function () {
    	tabContainers.hide().filter(this.hash).show();
        
		num_of_images = $(this.hash + ' .gallery_list li').size();
		cur_thumb_pos = 1;
		pagination();
		
		$('.tabs a').removeClass('active');
        $(this).addClass('active');
        
        return false;
    }).filter(':first').click();





	// Slide thumbnails left
	$('.gallery-pan-left').click(function() {
		if (cur_thumb_pos > 1) {
			$('.gallery_list').animate(
				{
					left: '+=' + frame_width
				}, "fast"
			);
			cur_thumb_pos--;
			$(".pagination li a").removeClass("active");
			$(".pagination li:nth-child(" + cur_thumb_pos + ") a").addClass("active");
		}

		return false;
	})
	.mouseover(function(){ $(this).attr({src: '/images/stepbystep/pan-left-over.png'}) })
	.mouseout(function(){ $(this).attr({src: '/images/stepbystep/pan-left.png'}) });
	//.css({ cursor: 'pointer' });
  	
	// Slide thumbnails right
	$('.gallery-pan-right').click(function() {
		if (cur_thumb_pos <= Math.ceil(num_of_images / images_per_frame - 1)) {
			$('.gallery_list').animate(
				{
					left: '-=' + frame_width
				}, "fast"
			);
			cur_thumb_pos++;
			$(".pagination li a").removeClass("active");
			$(".pagination li:nth-child(" + cur_thumb_pos + ") a").addClass("active");
		}

		return false;
	})
	.mouseover(function(){ $(this).attr({src: '/images/stepbystep/pan-right-over.png'}) })
	.mouseout(function(){ $(this).attr({src: '/images/stepbystep/pan-right.png'}) });
	//.css({ cursor: 'pointer' });

	pagination();

	function pagination()
	{
		var _link;
		$(".pagination").empty();
		$(".gallery_list").animate({left: '0'}, "fast");
		for (x=1; Math.ceil(num_of_images / images_per_frame) >= x; x++) {
			if (x == 1)
				_link = "<li><a href='#' alt='" + x + "' class='active'>" + x + "</a></li>";
			else
				_link = "<li><a href='#' alt='" + x + "'>" + x + "</a></li>";

			$(".pagination").append(_link);
		}

		var _goto;
		$(".pagination li a").click ( function() {
				cur_thumb_pos = $(this).attr("alt");
				if (cur_thumb_pos != 1)
					_goto = frame_width * (cur_thumb_pos-1);
				else
					_goto = 0;
				
				$('.gallery_list').animate(
					{
						left: -_goto
					}, "fast"
				);
						
				$(".pagination li a").removeClass("active");
				$(this).addClass("active");

				return false;
			}
		);
	}
	
	

$(".cover_image").click(function(){
	$(".cover_image").removeClass("active");
	$(this).addClass("active");
	var id = $(this).attr('id');
	$.ajax({
		type: "GET",
		url: "/mediaroom/getmention/id/" + id,
		dataType: "xml",
		success: function(xml) {
			$(xml).find('mention').each(function(){
				var image = $(this).find('image').text();
				var publisher = $(this).find('publisher').text();
				var excerpt = $(this).find('excerpt').text();
				var html = '<img src="/images/mediaroom/product_mentions/article/' + image + '" class="article_image" />';
				html += '<div><h2>' + publisher + '</h2><p>' + excerpt + '</p></div>';
				$(".content_area").html(html);
			});
		}
	});
	return false;
});



$(".video_thumb").click(function(){
	$(".video_thumb").removeClass("active");
	$(this).addClass("active");
	var id = $(this).attr('id');
	$.ajax({
		type: "GET",
		url: "/mediaroom/getvideo/id/" + id,
		dataType: "xml",
		success: function(xml) {
			$(xml).find('video').each(function(){
				var source = $(this).find('source').text();
				var image = $(this).find('image').text();
				var title = $(this).find('title').text();
				var caption = $(this).find('caption').text();
				var date = $(this).find('date').text();
				$(".title").html(title);
				$(".date").html(date);
				$(".caption").html(caption);
				$(".jwplayer").html('');
				$(".jwplayer").flash({
				    src: '/swf/mediaplayer.swf',
					width: 375,
					height: 250,
					wmode: 'transparent',
					flashvars: {file: source, autostart: true}
				});
			});
		}
	});
	return false;
});
	

}


