(function($){

$(window).load(function () {
	
	$(".font-face").css('visiblity', 'visible');
	
});

$(document).ready(function(){
	
	// cufon
	Cufon.replace('#introduction h1, #introduction p, .page-title, #sidebar h6, #aside h6, .page_subtitle p', { fontFamily: 'PF Square Sans Pro Light'});
	Cufon.replace('#introduction h1 span', { fontFamily: 'PF Square Sans Pro Thin' });	
	Cufon.replace('.live-chat p, .brochure p, .download, #main h1, .order-type, .page_subtitle p strong', { fontFamily: 'PF Square Sans Pro' });
	Cufon.replace('#introduction p a, #introduction .try-out, .section-col h6, .order-type .price, .order-type .price-alt, .feat-link, .demo-ss h4, .col-block h6, .box h4', { fontFamily: 'PF Square Sans Pro Medium' });
	// $(".font-face").css('visiblity', 'hidden');
	
	$(".sub-block").append('<div class="clear"></div>');
	$("#nav > ul > li:has(ul) > a:first-child").addClass("hoverable");
	// $("#nav > ul > li:has(ul) a:first-child span").addClass("hoverable");
	
	
	if( $('.collapsed-list').length ) {
		$(".collapsed-list").each(function() {
			$(this).find("li:gt(2)").hide();
		})		
	}

	
	$('.show-all a').each(function() {
		$(this).click(function() {
			if( $(this).parent().prev('.collapsed-list').find("li:hidden").length ) {
				$(this).parent().prev('.collapsed-list').find("li:hidden").slideDown();
				$(this).text("Show less").addClass('contract');
			} else {
				$(this).parent().prev('.collapsed-list').find('li:gt(2)').slideUp();
				$(this).text("Show more").removeClass('contract');
			}
			return false;
		})
	})
	
	// $('.show-less a').each(function() {
	// 	$(this).click(function() {
	// 		alert('mukodik');
			// $(this).parent().prev('.collapsed-list').find('li:gt(2)').hide();
			// $(this).text("Show more").parent().removeClass("show-less").addClass("show-all");
	// 		return false;
	// 	})
	// })
	
	$("#nav > ul > li:has(ul)").hover(
	      function () {
				$(this).addClass("hovered").find("ul").show();	
	      }, 
	      function () {
				$(this).removeClass("hovered").find("ul").hide();
	      }
	    );
	
	
		equalHeight($(".col-block li"));

		$('.search-text-input').each(function() {

			var usedinput = $(this);		
			var usedinputtitle = $(this).attr('title');
			
			$(this).click(remove)
			
			function remove() {
				if(usedinput.val() == usedinputtitle) {
					$(this).val("");
				}
			}
	
			$(this).blur(function() {
				if(usedinput.val() == "") {
					$(this).val(usedinputtitle);
					$(this).addClass('formError')
				} else {
					$(this).removeClass('formError')
				}
			}).focus(remove)
			
		
		});
		
		$('.NewsletterInputField').each(function() {

			var usedinput = $(this);		
			var usedinputtitle = $(this).attr('title');
			
			$(this).click(remove)
			
			function remove() {
				if(usedinput.val() == usedinputtitle) {
					$(this).val("");
				}
			}
	
			$(this).blur(function() {
				if(usedinput.val() == "") {
					$(this).val(usedinputtitle);
					$(this).addClass('formError')
				} else {
					$(this).removeClass('formError')
				}
			}).focus(remove)
			
		
		});

});

function equalHeight(group) {
         tallest = 0;
         group.each(function() {
             thisHeight = $(this).height();
             if(thisHeight > tallest) {
                 tallest = thisHeight;
             }
         });
         group.height(tallest);
     }
})(jQuery);