
function tab_load_first()
{
	jQuery('#ew_tabs_menu td:first a').eq( 0 ).trigger( 'click' );
}

function tab_load(link){
	jQuery('#ew_tabs_prev').css('visibility','visible')
	jQuery ('#ew_tabs_menu td').removeClass('active')
	jQuery (link.parent()).addClass('active')
	
	
	var c=jQuery('#ew_tabs_content')
		.addClass('loading')
		.empty()
		.load(
			link.attr('href')+' #ew_tabs_content_inner',
			function(){
				c.removeClass('loading')
			}
		);
		
	return false;
}

function tab_load_prev(link){
		var node=jQuery('#ew_tabs_menu td.active').prev().find('a')
		if(node.size()>0){
			tab_load(node)
		}
		else{
			tab_load(jQuery('#ew_tabs_menu td:last a'))
		}
}

function tab_load_next(link){
		var node=jQuery('#ew_tabs_menu td.active').next().find('a')
		if(node.size()>0){
			tab_load(node)
		}
		else{
			tab_load(jQuery('#ew_tabs_menu td:first a'))
		}
		
}

$(document).ready(tab_load_first);

function gallery_create( target_element, domain, image_ids ) {
	var size_w;
	
	if( screen.width<=1200 ) {
		size_w='1200';
	} else if( screen.width<=1600 ) {
		size_w='1600';
	} else{
		size_w='1920';
	}
	
	var images = [];
	jQuery.each( image_ids, function( i, image_str ) {
		var url = domain + '/(cms)/media/resize/size='+size_w+'x466,quality=70,interlace=1,scale=crop/'+image_str;
		images.push( {
			'href': url,
			'src': url
		} );
	})
	
	jQuery( target_element).vjg({
		'children': images,
		'view': 'multi',
		'offset': '3px',
		'timeout': 5000
	});
	
	function gallery_resize(){
		var offset = Math.round((size_w-$(window).width())/2);
		if( offset < 0 ) offset = 0;
		jQuery( 'a', target_element ).css('margin-left','-' +offset+'px')
	}
	
	$(window).resize(gallery_resize);
	gallery_resize();
}
