$(function() {
	
	v_collage();
	t_tabs();
	k_menu();
	
	$('.tabs-tabset:first').show();
	$('.tabs li:first').addClass('active');
	$('.tabs a').click(function(){
		$('.tabs li').removeClass('active');
		$(this).parent().addClass('active')
		$('.tabs-tabset').hide()
		$($(this).attr('href')).show();
		//		$(document).scrollTop(200);
		return false;
		
	})
	
	$('.view-News-list .views-row, .view-News-page .views-row, .view-Artists-page .views-row, .view-Reviews-page .views-row, .pager').append('<div class="shadow-top"></div><div class="shadow-bottom"></div>');
	
	$('.views-row').hover(function(){
		$(this).children('.shadow-top, .shadow-bottom').show();
	}, function(){
		$(this).children('.shadow-top, .shadow-bottom').hide();
	})
	
	
	$('fieldset legend').wrapInner('<div class="legend"></div>');
	$('fieldset .legend').append('<div class="rounded-top-left"></div><div class="rounded-top-right"></div>');
	
	
	
	$('.product .content .tabs-tabset:not(:first)').each(function(){
		$image_clone = $('.product .content .tabs-tabset .field-field-images .field-item:first').clone();
		$(this).prepend($image_clone);
		$image_clone.wrap('<div class="field field-type-filefield field-field-images"></div>');

	})
	 
	
	
	$('.field-field-full-image img, .views-field-field-side-image-fid img,.views-field-field-images-fid img, .field-field-images img, .views-field-field-video-embed object').each(function(){		
		$(this).after('<b></b>');
	})
	
	$('.block-search .form-submit').val(' ');
	$('#side h2').append('<b></b>');
	$('a img').hover(function(){$(this).animate({
	    opacity: 0.5
	  }, 500, function() {
	    // Animation complete.
	  });
	}, function(){$(this).stop().animate({
	    opacity: 1
	  }, 200, function() {
	    // Animation complete.
	  });
	});

		
});
function v_collage() {
	
	/**
	 * COLLAGE
	 */
	var slide_images_id = '.field-field-collage img';
	var $slide_images = $(slide_images_id);
	$slide_images.filter('img:first').addClass('active');
	if ($slide_images.length > 0)	{	
		autorotate_duration = 10;
		changing_duration = 5;
	
		$slide_images.not('.active').css({display:"none"});
		$slide_images.filter('.active').css({visibility:"visible"});
		// set the automatic image rotation, number is time between transitions in miliseconds
		interval = setInterval(function() { k_fader(slide_images_id,'1'); }, (parseInt(autorotate_duration) * 1000)); 	
	}	
}
function t_tabs() {
	$('.quicktabs_tabs').addClass('tabs');
	$('.tabs li').append('<div class="rounded-top-left"></div><div class="rounded-top-right"></div>');
}
function k_fader($items_to_fade, $next_or_prev){	
	var $items = jQuery($items_to_fade);
	var $currentitem = $items.filter(":visible");
	var $new_item;
	var $selector;
	
	$items.css('visibility','visible');
	
	if($items.length > 1)
	{
		for(i = 0; i < $items.length; i++)
		{
			if($items[i] == $currentitem[0])
			{	
				$selector = $next_or_prev >= 0 ? i != $items.length-1 ? i+1 : 0 : i == 0 ? $items.length-1 : i-1;
				
				$new_item = jQuery($items[$selector]);
				break;
			}
		}
		
		if( $new_item && $new_item.css("display") == "none" )
			{	
				$currentitem.css({zIndex:2});
				$new_item.css({zIndex:3}).fadeIn(changing_duration * 1000, function()
				{
					$currentitem.css({display:"none"});
				});
				
			}
	}
}

function k_menu()
{
	$('.navigation ul:first').attr('id', 'nav');
	//$('.navigation .leaf, .navigation .expanded, .navigation .menu').removeClass('leaf').removeClass('expanded').removeClass('menu');
	$('.navigation').show();

	jQuery("#nav a, .subnav a").removeAttr('title');
	jQuery(" #nav ul ").css({display: "none"}); // Opera Fix
	
	jQuery("#nav li").each(function()
	{	
			
		var $sublist = jQuery(this).find('ul:first');
		
		jQuery(this).hover(function()
		{
						
			if (jQuery(this).parent('ul').attr('id') == 'nav' && !jQuery(this).is('.active-trail')) {
				if ($(this).children('b').length == 0 ) $(this).append('<b></b>');
				$(this).children('b').animate({
				    opacity: 1
				  }, 500, function() {
					//jQuery(this).parent().addClass('active');
				  });
			}
			$sublist.stop().css({overflow:"hidden", height:"auto", display:"none"}).slideDown(400, function()
			{
				jQuery(this).css({overflow:"visible", height:"auto"});
			});	
		},
		function()
		{
			if (jQuery(this).parent('ul').attr('id') == 'nav' && !jQuery(this).is('.active-trail')) {
				
				$(this).children('b').stop().animate({
				    opacity: 0
				  }, 200, function() {
					//jQuery(this).parent().removeClass('active');
				  });
			}
			$sublist.stop().slideUp(400, function()
			{	
				jQuery(this).css({overflow:"hidden", display:"none"});
			});
		});	
	});
}
