$(function() {

	$('.field').each(function(){if (this.value == "") { this.value = this.title; }});

	$('.field').focus(function() {
        if(this.title==this.value) {
            this.value = '';
            $(this).addClass('field-state-active');
        }
	$(this).parent().parent().addClass('helperactive');
	$(this).parent().parent().children('.helptext').css('display','block');

    }).blur(function(){
        if(this.value=='') {
            this.value = this.title;
            $(this).removeClass('field-state-active');
        }
	$(this).parent().parent().children('.helptext').css('display','none');
	$(this).parent().parent().removeClass('helperactive');
    });


// Pete Mod
	$('form').submit(function() {
                $('.field').each(function() { if (this.title == this.value) { this.value="";}});

        });

    
    $('a[rel=scroll]').live('click', function() {
    	$.scrollTo($(this).attr('href'), 800, {
    		offset: {
    			top: -61
    		}
    	});
    	return false;
    });
	
    $('.btn').hover(function() {
    	$(this).addClass('btn-hover');
    }, function() {
    	$(this).removeClass('btn-hover');
    });
    
    $('.blogs-list .item, .features-list .item').hover(function() {
    	$(this).addClass('item-hover');
    }, function() {
    	$(this).removeClass('item-hover');
    });
    
    $('.question-tip').bt({
    	padding: '10px 15px',
    	closeWhenOthersOpen : true,
    	overlap : '0',
	    width: 180,
	    spikeLength: 19,
	    spikeGirth: 22,
	    cornerRadius: 5,
	    fill: '#fff',
	    animate: false,
	    strokeWidth: 1,
	    strokeStyle: '#ddd',
	    shadow: true, 
		shadowBlur: 10,
		shadowOffsetX: 0,
		shadowOffsetY: 0,
		shadowColor: '#111',
    	shadowOverlap: false,
    	noShadowOpts: {strokeStyle: '#ddd', strokeWidth: 1},
	    positions: ['left', 'right'],
	    cssStyles: {color: '#3f3f3f', fontSize: '12px' }
    });
    
    $('.features-list .item').live('click', function() {
    	var href = $(this).find('a').attr('href');;
	var title = $(this).find('a').attr('title');
    	jQuery.facebox({ ajax: href });
	if (title) {
		var carousel = jQuery('.carousel').data('jcarousel');
		carousel.scroll(jQuery.jcarousel.intval(title));
	}
    });
    
    $('a[rel*=facebox]').facebox();
    
    $('#facebox .close').live('click', function() {
    	$(this).trigger('close.facebox');
    	return false;
    });
    
    $(document).bind('reveal.facebox', function() {
    	pageLoaded();
    });
});

function pageLoaded() {
	
	$('select.custom-select').sSelect({ddMaxHeight: '300px'});
	
	$('input[type=checkbox]').ezMark();
	
	$('.pricing-table tr:even').addClass('even');
	
	$('.field').each(function() {
		if(this.title!==this.value) {
            $(this).addClass('field-state-active');
        } else {
        	$(this).removeClass('field-state-active');
        }
	});
	$('input.custom-field').each(function() {
		if ($(this).parents('.field-holder:eq(0)').length) {
			return;
		};
		$(this).wrap('<div class="field-holder"></div>');
		$(this).parent().append('<span class="end">&nbsp;</span>');
	});
	$('textarea.custom-field').each(function() {
		if ($(this).parents('.textarea-holder:eq(0)').length) {
			return;
		};
		$(this).wrap('<div class="textarea-holder"></div>');
		$(this).parent().append('<span class="end">&nbsp;</span>');
	});
	
	function callback(carousel) {		
		var btn = carousel.container.find('.jcarousel-prev, .jcarousel-next');
		btn.css('opacity', '0');
		btn.hover(function() {
			$(this).css('opacity', '1');
		}, function() {
			$(this).css('opacity', '0');
		});
		
	}
	
	$('.carousel').jcarousel({
		'scroll' : 1,
		'wrap' : 'both',
		initCallback : callback
	});
}

