//home page slider

$(document).ready(function(){
	var slider_area;
	var slider_buttons;

	// Which slider
	if ($('#slider_area > div.slide').length>1){
		
		// Home Page Slider
		slider_area="#slider_area";	
		slider_buttons="#numbers";
	
	
		$(slider_area).cycle({ 
			fx:     'fade', 
			timeout:  7000,
			//easing: 'backout', 
			prev: '.prev', 
			next: '.next',
			cleartype:  1,
			pause:           true,     // true to enable "pause on hover"
			pauseOnPagerHover: true,   // true to pause when hovering over pager link				
			before:  onBefore, 
			after:   onAfter ,				
			pagerAnchorBuilder: function(idx) { 
				return '<a href="#" title=""><img src="images/pixel.gif" width="14" heigth="14"></a>'; 
			}
		});
		
	}
	
	if ($('#slider_area2').length>0){
		
		// Home Page Slider
		slider_area="#slider_area2";	
		slider_buttons="#numbers2";
	
	
		$(slider_area).cycle({ 
			fx:     'fade', 
			timeout:  4000,
			//easing: 'backout', 
			prev: '.prev', 
			next: '.next',
			cleartype:  1,
			pause:           true,     // true to enable "pause on hover"
			pauseOnPagerHover: true,   // true to pause when hovering over pager link				
			before:  onBefore, 
			after:   onAfter ,				
			pagerAnchorBuilder: function(idx) { 
				return '<a href="#" title=""><img src="images/pixel.gif" width="14" heigth="14"></a>'; 
			}
		});
		
	}	
	
	

	if ($('.product_detail').length>0){
		
		// Home Page Slider
		slider_area_pp=".product_photos";	

		$(slider_area_pp).cycle({ 
			fx:     'fade', 
			timeout:  4000,
			pager:'.product_photos_pager',
			cleartype:  1
		});
		
	}
	
	
jQuery('.prev, .next').css({opacity:0});
jQuery('#slider').hover(function()
{
	jQuery('.prev, .next').stop().animate({opacity:1},400);
},
function()
{
	jQuery('.prev, .next').stop().animate({opacity:0},400);
});


function onBefore() { 
	jQuery('.desc').stop().animate({opacity:0.9},400);
} 
function onAfter() { 
	jQuery('.desc').stop().animate({opacity:0.9},400);
}

	
});



//pretty photo
$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto();
});


//image effects 
$(document).ready(function(){
		var image_e= $(".image.portf, .image.product_image");
		image_e.mouseover(function(){$(this).stop().animate({ opacity:0.4
				}, 400);
		}).mouseout(function(){
			image_e.stop().animate({ 
				opacity:1
				}, 400 );
		});
});

//validate contact form
$(document).ready(function(){

	// show a simple loading indicator
	var loader = jQuery('<em>Proszę czekać...</em>')
		.appendTo(".loading:first")
		.hide();
	jQuery().ajaxStart(function() {
		loader.show();
	}).ajaxStop(function() {
		loader.hide();
	}).ajaxError(function(a, b, e) {
		throw e;
	});
	
	jQuery.validator.messages.required = "";
	jQuery.validator.messages.email = "";
	
	var v = jQuery('#validate_form');
	
	v.each(function(){
		//var tar = $(this).next('div').attr('id');
		$(this).validate({
		
		
		submitHandler: function(form) {
			
			jQuery(form).ajaxSubmit({
				target: "#result:first",
				success: function(responseText){
					jQuery(this).prev().slideUp();
				}
			});
		}
	});
	});
	
	
	
	
	jQuery("#reset").click(function() {
		v.resetForm();
	});
 });










//cufon fonts
//$(document).ready(function(){
//		
//	var cufon_list="h1,h2,h3,h4,h5,h6"
//	var rt_cufon_class = jQuery(cufon_list);	
//
//	rt_cufon_class.each(function(){
//		 jQuery(this).addClass('cufon');
//	});
//
//	Cufon.replace(cufon_list, {hover: true});
//	Cufon.replace('.cufon_replace', {hover: true,fontFamily: 'Myriad Pro' });
//});

$(document).ready(function(){
	Cufon.replace('h2.cufon', {hover: true});
});
	

 

//search field function
$(document).ready(function() {
	var search_text=jQuery(".search_bar .search_text").val();

	jQuery(".search_bar .search_text").focus(function() {
		jQuery(".search_bar .search_text").val('');
	})

});


//preloading 
$(function () {
	//$('.preload').hide();//hide all the images on the page
	$('.play,.magnifier').css({opacity:0});
	$('.preload').css({opacity:0});
	$('.preload').addClass("animated");
	$('.play,.magnifier').addClass("animated_icon");
});

var i = 0;//initialize
var cint=0;//Internet Explorer Fix
$(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
	var cint = setInterval("doThis(i)",70);//500 is the fade in speed in milliseconds

});

function doThis() {
	var images = $('.preload').length;//count the number of images on the page
	if (i >= images) {// Loop the images
		clearInterval(cint);//When it reaches the last image the loop ends
	}
	//$('.preload:hidden').eq(i).fadeIn(500);//fades in the hidden images one by one
	$('.animated_icon').eq(0).animate({opacity:1},{"duration": 500});
	$('.animated').eq(0).animate({opacity:1},{"duration": 500});
	$('.animated').eq(0).removeClass("animated");
	$('.animated_icon').eq(0).removeClass("animated_icon");
	i++;//add 1 to the count
}



$(document).ready(function() {
    
$('#tooltip_zoom').tooltip({effect: 'slide'});    

/*
$(".photo_gallery img[title]").tooltip({

   // tweak the position
   offset: [40, 0],

   // use the "slide" effect
   effect: 'slide'

// add dynamic plugin with optional configuration for bottom edge
}).dynamic({ bottom: { direction: 'down', bounce: true } });
*/    
});

/* jest w contact.js
$(document).ready(function() {
	jQuery("#datepicker").datepicker($.datepicker.regional['pl']);
	jQuery("#time").timePicker({
		  startTime: "10:00", // Using string. Can take string or Date object.
		  endTime: new Date(0, 0, 0, 19, 30, 0), // Using Date object here.
		  show24Hours: true,
		  separator: ':',
		  step: 15});
});*/

$(document).ready(function() {
	
	var submenu = jQuery('#menu li ul');
	
		
	submenu.each(function(){
		var act = false;
		
		var sublinks = $(this).find('a');
			sublinks.each(function(){
				if($(this).hasClass("active")){
					act = true;
				}
				//alert(act);
			});
		
		
		if(!$(this).prev().hasClass("active") && !act){
			$(this).hide();
		}
		
	});
	
	
});






