$(document).ready(function($) {

	var currentimage = $('.gallery_preview a.current').attr('title');

	$(window).load(function(){

			var c = 1;

			$('.gallery_preview img').each(function(i){
				if(c != currentimage){
				$("#bigimg").append('<img src="'+$(this).attr('alt')+'" alt="" id="image'+c+'" class="mainimage" style="display: none;"/>');
				}
				c++;

			});

		});
		
		var counter = $('.gallery_preview a.current').attr('title');

		

		var all = $('.gallery_preview').attr('title');

		$('a.next, #bigimg').click(function() { 

			counter++;
            
			

			if (counter > all) { counter = 1; // $('#button_right').attr('href', '#1'); $('a.imgnext').attr('href', '#1'); 
			}
			var cm = $('.gallery_preview a[title='+counter+'] img').attr('class');	
				$("#bigimg img:visible, div.numbers .cimg").fadeOut(1000, function(){
			    $("div.numbers span.cimg").text(cm);
				$('#bigimg img#image'+counter+', div.numbers .cimg').fadeIn(1000);

			});
		
			return false;

		});

		$('#bigimg').css('cursor', 'pointer');

		$('a.previos').click(function() { 

			counter--;
          
			if (counter == 0) { counter = all; // $('#button_right').attr('href', '#1'); $('a.imgnext').attr('href', '#1'); 
			}
			  var cm = $('.gallery_preview a[title='+counter+'] img').attr('class');	
				$("#bigimg img:visible, div.numbers .cimg").fadeOut(1000, function(){
			    $("div.numbers span.cimg").text(cm);
				$('#bigimg img#image'+counter+', div.numbers .cimg').fadeIn(1000);

			});
		
			return false;

		});

		$('.gallery_preview a').click(function() { 
	
			if(currentimage != undefined){
				
				counter = $(this).attr('title');

              var cm = $('.gallery_preview a[title='+counter+'] img').attr('class');

				if ($("#bigimg img:visible").attr('id') != 'image'+counter)	{			
				
					$('.gallery_preview a.current').removeAttr('class');

					$(this).attr('class', 'current');				

					$("#bigimg img:visible, div.numbers .cimg").fadeOut(1000, function(){
							$("div.numbers span.cimg").text(cm);
						$('#bigimg img#image'+counter+', div.numbers .cimg').fadeIn(1000);

					});
				}
			return false;
			}
		});				
				
		// $('a.imgnext').click(function() { 

		//		counter++;
				
		//		$('#button_right').attr('href', '#'+counter);

		//		$('a.imgnext').attr('href', '#'+counter);

		//		if (counter > all) { counter = 1; $('a.imgnext').attr('href', '#1'); $('#button_right').attr('href', '#1'); }
				
		//		$("#img_wrapper img:visible").fadeOut(1000, function(){
						
		//				$('#img_wrapper img#'+counter+'image').fadeIn(1000);

		//	    });
		// });
		
		$('#music ul.text').css('display', 'none');
		visible = 0;
		$('#music h3').css('cursor', 'pointer').click(function(h3) {

				id = $(this).attr('id');
				// $('#music #text h3').css('color', '#aaa');
				
				// $(this).css('color', '#444');
				
				if (visible > 0)
				{				
				$("#music ul:visible").fadeOut(1000, function (){

				$('#music ul#'+id+'mid').fadeIn(1000);
				});
				}

				if (visible == 0)
				{	$('#music ul#'+id+'mid').fadeIn(1000);
					
				}
				visible++;
		});

		$('#music h3.first').removeAttr('style');
		$('#music h3#othermusic').css('cursor', 'pointer');
	}); 