(function($){
	$( document ).ready( function(){		
		
		Cufon.replace('.sub-nav ul li a span',{fontFamily:'MyriadMMRegular'});
		
		$('#navigation ul.sub-menu').each(function(){
			$(this).find('> li:last').addClass('last');
		})
		
		$('#navigation ul li').hover(function () {
			$(this).addClass('hover');
			$(this).find('ul').show()
		}, function () {
			$(this).removeClass('hover');
			$(this).find('ul').hide()
		})
		
		$('#slider').jcarousel({
			auto: 5,
			scroll: 1,
			wrap: 'both'
		})
		
		checkTabs();
		
		$('.tabbed-box .tabs-nav li a').live('click', function () {
			var href = $(this).attr('href');
			var tabs = $(this).parents('.tabbed-box:eq(0)').find('.tabs-content:eq(0)');
			$(this).parents('ul:eq(0)').find('a').removeClass('active');
			$(this).addClass('active');
			tabs.find('.tab-cnt').hide();
			$(this).parents('.tabbed-box').find(href).show();
			return false;
		})
		
		$('.gform_wrapper form').submit(function(){
			$(this).find('input, textarea').each(function(){
				var tit = $(this).attr('title');
				var val = $(this).val();
				if ( val != '' && tit != '' && tit == val ) {
					$(this).val('');
				};
			})
			
		})
		
		$('.gform_fields .gfield textarea').each(function(){
			var val = $(this).val();
			var tit = $(this).attr('title');
			if ( (tit == '' || tit == undefined) && ( val != '' || val == undefined ) ) {
				$(this).attr('title', val);
			};
		})
		
		$('#main .gform_fields').each(function(){
			if ( $(this).find('span.gfield_required').length != 0 ) {
				if ( $(this).parents('.gform_wrapper').find('.gform_footer p.right').length == 0 ) {
					$(this).parents('.gform_wrapper').find('.gform_footer').append('<p class="right">*Required field</p>')
				}
				
			};
		})
		
		$('input, textarea')
			.focus(function(){
				if ( $(this).attr('value') == $(this).attr('title') ) {
					$(this).attr({ 'value': '' })
				}
			})
			.blur(function(){
				if ( $(this).attr('value') == '' ) {
					$(this).attr({ 'value': $(this).attr('title') })
				}
			})
			
		$('.question-link').live('click', function () {
			$(this).parents('.question-list').find('.answer').stop(true, true).slideUp();
			$(this).parents('.question-list').find('.active').removeClass('active');
			$(this).parent().stop(true, true).toggleClass('active');
			$(this).parent().find('.answer').slideDown();
			return false;
		})
		
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
			DD_belatedPNG.fix('h1#logo a, .shop-btn, #navigation, #slider, .title, .advantage1, .advantage2, .advantage3, #footer, .page-title h1, .sub-nav ul, #main-content ');
		};
		
		$.fixpng();
	});
	
	function centerNavigation() {
		var	holderWidth = $('#navigation').width();
		var	innerWidth = $('#navigation ul').width();
		var padding = (holderWidth - innerWidth)/2;
		$('#navigation > ul').css('padding-left', padding);
	}
	
	$(window).load(function () {
		centerNavigation();
		centerProducts();
	})
	
	function centerProducts() {
		var	holderWidth = $('.products-list').width();
		var	innerWidth = $('.products-list  ul').width();
		var padding = (holderWidth - innerWidth)/2;
		$('.products-list ul').css('padding-left', padding);
	}
	
	function checkTabs() {
		$('.tabbed-box').each(function () {
			var href = $(this).find('.tabs-nav li a.active').attr('href');
			$(this).find(href).show();
		})
	};
})(jQuery)
