$(document).ready(function(){
	
	////// SMOKE ANIMATION //////////////////////////////////////////

	$('body').append('<div id="smoke1"></div><div id="smoke2"></div>');
	
	setInterval("bloooming_smoke('smoke1','smoke2')", 50);
	
		
	///// SHOW LOADING IMAGE ON AJAX ACTIVITY ////////////////
	$('.ajax')
		.hide()  // hide it initially
		.ajaxStart(function() {
			$(this).show();
		})
		.ajaxStop(function() {
			$(this).delay(350).fadeOut();
		});

	///// SLIDER 1,2,3 ////////////////////////////////////////

	$('#slider1').anythingSlider({
		easing: 'swing',
		autoPlay: true,
		delay: 3000,
		animationTime: 1000
	});
	
	$('#slider2').nivoSlider({
		pauseOnHover:true,
		directionNav:true, 
		directionNavHide:false,
		animSpeed:500, //Slide transition speed
		pauseTime:6000
	});

	$('#slider3').anythingSlider({
		easing: 'swing',
		autoPlay: true,
		delay: 3000,
		animationTime: 1000
	});
	
	
	//// wrap the #thumbNav div to create a flexible slider
	
	$('#thumbNav').wrap('<div id="thumbOuter" />');
	$('.nivo-controlNav').wrap('<div id="thumbOuter2" />');
	$('#thumbNav').show();
	
	$('#thumbOuter2').appendTo('#slider2wrapper');
	$('.nivo-directionNav').appendTo('#slider2wrapper');
	
	
	//// CURVY CORNERS ON IMAGES FOR FIREFOX //////////////////////////

	$('#tabs img').bloooming_roundPic();
	$('.content_left img').bloooming_roundPic();
	$('.content_right img').bloooming_roundPic();



	//// TABS ////////////////////////////////////////////
	
	$(".tabcontent").hide(); 
	$("ul.tabs li:first").addClass("active").show(); 
	$(".tabcontent:first").show(); 


		//On Click Event
		$("ul.tabs li").click(function() {
			$("ul.tabs li").removeClass("active"); 
			$(this).addClass("active"); 
			$(".tabcontent").hide(); 
			var activeTab = $(this).find("a").attr("href"); 
			$(activeTab).fadeIn(); 
			return false;
		});
	
	$('.logo_small').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});
	
	
	//// CUFON ////////////////////////////////////////////

	Cufon.replace('h1');
	Cufon.replace('h2');
	Cufon.replace('h3');
	Cufon.replace('.price');
	

	//// COLLAPSIBLE MENU //////////////////////////////////
	$(".productsmenu > li > a").mouseover(function(){
		if($(this).children('ul').is(':visible') == false) {
			$(this).next().show(800);
		}
	});
	
	$('.productsmenu > li ul:first').show();

	$('.content_right .littlegal li').bloooming_alternate(2);
	
	//// SHOP FUNCTIONS //////////////////////////////////

	$('.products').bloooming_shop();


	//// GALLERIES FUNCTIONS //////////////////////////////////

	$('.zoom').colorbox({
		opacity:0.6
	});
	

	$('.videozoom').colorbox({
		iframe:true, innerWidth:425, innerHeight:344
	});
	
	$('.zoom').bloooming_picHover();
	$('.videozoom').bloooming_picHover();
	
	
	//// CONTACT FORM //////////////////////////////////

	$('.submit').click(function(){

		var name = $('#name').val();
		var email = $('#email').val();
		var phone = $('#phonenumber').val();
		var message = $('#message').val();
		var valid = true;
		
		if (name == '' || name == $('#name').attr('title')) {
			$('.name-error').show();
			valid = false;
		} else {
			$('.name-error').hide();
		}
		
		if (email == '' || email == $('#email').attr('title')) {
			$('.email-error').show();
			valid = false;
		} else {
			$('.email-error').hide();
		}
		
		if (message == '' || message == $('#message').attr('title')) {
			$('.message-error').show();
			valid = false;
		} else {
			$('.message-error').hide();	
		}
		
		// send data with ajax
		
		var formData = 'name='+ name + '&email=' + email + '&phone=' + phone + '&message=' + message;
		
		if (valid == true) {
			$.ajax({
				type : 'POST',
				url : 'lib/send.php',
				data : formData,
				success : function () {
					$('.error').hide();
					$('#name').val('');
					$('#email').val('');
					$('#phonenumber').val('');
					$('#message').val('');
					$('#form').hide();
					$('.thx').show();
				}
			});
		} // valid

				
		return false;
	
	});


});
