// on dom ready
$(document).ready(function(){

	// stripe tables
	$('table.stripe tr:odd').addClass('odd');

	// hide elements
	$('.hide').hide();

	// change package
	$('#package').change(function(){
		// get value
		var selected = $(this).val();

		// show video upload
		if(selected == 'Media' || selected == 'Platinum') {
			$('.video').show();
		} else {
			// hide video upload
			$('.video').hide();
		}

		// change word count
		if(selected == 'Platinum') {
			$('.word_count').html('400');
		} else {
			$('.word_count').html('100');
		}
	});

	// get current count
	if( $('#text').length > 0 ) {
		if( $('#text').val().length > 0 ) {
			$('#count').html($('#text').val().split(/\b[\s,\.-:;]*/).length);
		}
	}

	// change count on keyup
	$("#text").keyup(function() {
     	$('#count').html($('#text').val().split(/\b[\s,\.-:;]*/).length);
	});


	// show preview
	$('.preview_show').hover(
		function(){
			//console.log('show');
			$('.preview_box').show();
		},
		function(){
			//console.log('hide');
			$('.preview_box').hide();
		}
	);
	
	// deal with more info on horses for sale
	tooltips();
});


function tooltips() {
	var title;
	var position = function(e) {
		var posX = e.pageX + 10;
		var posY = e.pageY;
		//console.log( posX + ':' + posY );
	};
	var show_tooltip = function(i) {
		$('.tooltip').remove();
		title = i.attr('title');
		if(title != '') {
			i.attr('title','');
			i.after('<div class="tooltip"><p>'+title+'</p></div>');
			$('.tooltip').fadeIn("normal");
			//$('.tooltip').show().css({'opacity':0}).animate({opacity:0.9},300);
			if( $('.tooltip').width()>400 ) {
				$('.tooltip').css({width:"400px"});
			}
		}
	};
	var hide_tooltip = function(i) {
		i.attr('title',title);
		$('.tooltip').fadeOut("normal",function(){$('.tooltip').remove();});
	};
	$('.more_info').hover(
		function(e) {
			show_tooltip($(this));
		},
		function(e) {
			hide_tooltip($(this));
		}
	).mousemove(position).click(function(){return false;});
}