//Document Ready
jQuery(function($) {
	

	//Blink Fields
	 $('.blink').
	    focus(function() {
	        if(this.title==this.value) {
	            this.value = '';
	        }
	    }).
	    blur(function(){
	        if(this.value=='') {
	            this.value = this.title;
	        }
	    });
	    
	//Testimonials Scroll
	$('#testimonials .categories a').click(function(){ 
		var idx = $(this).parent().index() + $(this).parent().parent().parent().index()*3;
		var scrollPos = $('#testimonials .category').eq(idx).offset().top - 10;
		$('html,body').animate({
			scrollTop: scrollPos
		})
		return false;
	});
	
	//Cart Overview Custom Select
	
	//Scroll Customer Service  page
	$(document).ready(function() {
$('.CustomerService').click(function() {
   var elementClicked = $(this).attr("href");
   var destination = $(elementClicked).offset().top;
   $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
   return false;
});
});	
	
	//Add Even Class for Press Releases Tabel
	$('.press-releases tr:even').addClass('even');
	
	//Call Colorbox Popup
	//	$('.videotour_widget .link').colorbox({
		//	opacity : 0.6
		//});
	$("#watch_the_video").click(function(){		
   	$('.lightBoxMain').modal();
  	
  });
	$("#watch_the_video2").click(function(){		
   	$('.lightBoxMain2').modal();
  	
  });
	$("#watch_the_video_middle").click(function(){		
   	$('.lightBoxMain_Middle').modal();
  	
  });

	//Set Active Class for product tabs
	$('#product .product-tabs li:eq(0) a').addClass('active');
	$('#product .tab:eq(0)').show();
	
	//Click States
	$('#product .product-tabs li a').click(function(){ 
		var clickedIdx = $(this).parent().index();
		$('#product .tab').hide();
		$('#product .product-tabs a').removeClass('active');
		$(this).addClass('active');
		$('#product .tab').eq(clickedIdx).show();
		return false; 
	 });
	 
	 //Font Size Control
	 $('.font-control a').click(function(){ 
	 	var elementId = $(this).attr('id');
	 	var currentFontSize = parseInt($('#product .tabs-holder').css('font-size'));
	 	if (elementId == 'decrease') {
	 		currentFontSize -= 2;
	 		$('#product .tabs-holder').css({
	 			'font-size':  currentFontSize
 			});
	 	}
	 	if (elementId == 'increase') {
	 		currentFontSize += 2;
	 		$('#product .tabs-holder').css({
	 			'font-size':  currentFontSize
 			});
	 	}
	 	return false;	
 	});
 	
 	if (!$('ul.post-breadcrumbs li').length) {
 		$('ul.post-breadcrumbs').remove();
 	}
 	
 	//PNG Fix 
 	if($.browser.msie && parseInt($.browser.version) == 6 ){
 		DD_belatedPNG.fix('#logo a, #login-block, #footer, .sidebar-left-t, .sidebar-left-b, .sidebar-left-cnt, .overlay, #content-inner, #search, .add-to-cart, .widget, .product-overview img.left, .download-pdf');
 	}
	
	$('.validate').submit(function() {
		var valid = true;
		var errors = '';
		
		$(this).find('.required').each(function() {
			if ($(this).val() == '') {
				$(this).addClass('field-error');
				errors += 'The "' + $(this).attr('title') + '" field is required\n';
				if (valid) {
					$(this).focus();
				}
				valid = false;
			} else {
				$(this).removeClass('field-error');
			}
		});
		
		$(this).find('.email').each(function() {
			var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
			
			if (!pattern.test($(this).val())) {
				$(this).addClass('field-error');
				errors += 'The email address you entered is not valid\n';
				if (valid) {
					$(this).focus();
				}
				valid = false;
			} else {
				$(this).removeClass('field-error');
			}
		});
		
		if (!valid) {
			alert(errors);
		}
		
		return valid;
	});
});

