$(document).ready(function(){


	Cufon.replace('form label', { fontFamily: 'font_paine'});
	Cufon.replace('div.head p', { fontFamily: 'font_paine', hover: false});
	Cufon.replace('ul.pagination li a', { fontFamily: 'font_paine', hover: true});
	Cufon.replace('form p.sub_title', { fontFamily: 'font_paine'});
	Cufon.replace('#msg_success span.description', { fontFamily: 'font_paine'});


	$('#contest_pictures li.contest_picture a').click(function(){
		$m = $(this).attr('href');
		var xhtml=$.ajax({
		type: "GET",
		cache: false,
		async: false,
		url: $m
		}).responseText;
		
		temp_xhtml = new Array();
		temp2_xhtml = new Array();

		temp_xhtml = xhtml.split('<!--START-CUT-HERE-->',2);
		temp2_xhtml = temp_xhtml[1].split('<!--END-CUT-HERE-->',1);
		$('#ajax_cnt').html(temp2_xhtml[0]);
		return false;
	});


	$('#ajax_cnt div.contest_picture p.pagination a').live('click', function() {
		$n = $(this).attr('href');
		var xhtml=$.ajax({
		type: "GET",
		cache: false,
		async: false,
		url: $n
		}).responseText;
		
		temp_xhtml = new Array();
		temp2_xhtml = new Array();

		temp_xhtml = xhtml.split('<!--START-CUT-HERE-->',2);
		temp2_xhtml = temp_xhtml[1].split('<!--END-CUT-HERE-->',1);
		$('#ajax_cnt').html(temp2_xhtml[0]);
		return false;
	});

	$('div.tips_tricks_cnt ul.pagination li a').live('click', function() {
		$n = $(this).attr('href');
		var xhtml=$.ajax({
		type: "GET",
		cache: false,
		async: false,
		url: $n
		}).responseText;
		
		temp_xhtml = new Array();
		temp2_xhtml = new Array();

		temp_xhtml = xhtml.split('<!--START-CUT-HERE-->',2);
		temp2_xhtml = temp_xhtml[1].split('<!--END-CUT-HERE-->',1);
		$('div.tips_tricks_cnt').html(temp2_xhtml[0]);
		Cufon.replace('ul.pagination li a', { fontFamily: 'font_paine', hover: true});
		return false;
	});



	$('div.contest_picture form#vote input.submit').live("click", function(){
		$(this).parent().parent().ajaxForm(
			{
				//target:			'div',										// target element(s) to be updated with server response
				//beforeSubmit:		showRequest,								// pre-submit callback
				success:       		parse_contest_picture_vote_response,		// post-submit callback
				// other available options:
				url:       			$(this).parent().parent().attr('action'),	// override for form's 'action' attribute
				type:      'post',        										// 'get' or 'post', override for form's 'method' attribute
				//dataType:  null												// 'xml', 'script', or 'json' (expected server response type)
				//clearForm: true												// clear all form fields after successful submit
				//resetForm: true												// reset the form after successful submit
				// $.ajax options can be used here too, for example:
				timeout:   3000
			}
		);
	});
	
	function parse_contest_picture_vote_response(responseText, statusText, xhr, $form)
	{
		 if (responseText == '')
		 {
//				 alert(responseText);
			 $('#vote_submit').addClass('voted');
			 $('div.recaptcha').addClass('voted');
			 nr_voturi = parseInt($('#ajax_cnt p.vote span').html());
			 nr_voturi++;
			 $('#ajax_cnt p.vote span').html(nr_voturi);
		 }

//		 $('#ajax_cnt').append(responseText);





		temp_xhtml = new Array();
		temp2_xhtml = new Array();

		temp_xhtml = responseText.split('<!--START-CUT-HERE-->',2);
		temp2_xhtml = temp_xhtml[1].split('<!--END-CUT-HERE-->',1);
		$('#ajax_cnt').html(temp2_xhtml[0]);
//		Cufon.replace('ul.pagination li a', { fontFamily: 'font_paine', hover: true});
		return false;


	}






	$('#navigation li').hover(function(){
		if ($(this).hasClass('selected'))
		{
			do_nothing = true;
		} else {
			$(this).addClass('selected');	
			do_nothing = false;
		}
	},function(){
		if (do_nothing == false)
		{
			$(this).removeClass('selected');	
		}
	});


	$('#sub_menu li').hover(function(){
		if ($(this).hasClass('selected'))
		{
			do_nothing = true;
		} else {
			$(this).addClass('selected');	
			do_nothing = false;
		}
	},function(){
		if (do_nothing == false)
		{
			$(this).removeClass('selected');	
		}
	});


	$('div.body_retete div.cat').hover(function(){
		$(this).addClass('cat_hover');
	},function(){
		$(this).removeClass('cat_hover');
	});

	$('div.sorting ul li').hover(function(){
		$(this).addClass('sort_hover');
	},function(){
		$(this).removeClass('sort_hover');
	});

	$('#masini p.more').click(function(){
		$('p.more').addClass('hidden');
		$(this).next('div.description').addClass('visible');
	});

	$('#masini p.visual').click(function(){
		$('p.more').addClass('hidden');
		$(this).next().next('div.description').addClass('visible');
	});

	$('p.contest_participa a').click(function(){
		$('div.frm_register').addClass('visible');
		return false;
	});

	$('p.enter_contest').click(function(){
		$('div.frm_register').addClass('visible');
		return false;
	});

	$('p.add_tip').click(function(){
		$('div.frm_tips_and_tricks').addClass('visible');
		return false;
	});

	$('p.add_recipe').click(function(){
		$('div.frm_recipe').addClass('visible');
		return false;
	});

	$('p.close').click(function(){
		$('p.more').removeClass('hidden');
		$(this).parent().removeClass('visible');
		$('div.gift_yes_or_ney').addClass('hidden');
	});

	$('p.close').live('click',function(){
		$('p.more').removeClass('hidden');
		$(this).parent().removeClass('visible');
		$('div.gift_yes_or_ney').addClass('hidden');
	});

	if ($('p.error').length>0)
	{
		$('div.frm_register').addClass('visible');
		$('div.frm_recipe').addClass('visible');
		$('div.frm_tips_and_tricks').addClass('visible');
	}

	$pag_sape = 0;
	$('ul.pagi_tips li.pos1 a').click(function(){
		if ($(this).parent().hasClass('disabled'))
		{
			return false;
		} else {
			if ($pag_sape > 0)
			{
				$('ul.pagi_tips li').removeClass('disabled')
				$pag_sape--;
				$('ul.tips_and_tricks').animate({
					left: '+=205'
				}, 1000, function() {
					// Animation complete.
				});
			}
		}
		return false;
	});

	$('ul.pagi_tips li.pos2 a').click(function(){
		if ($(this).parent().hasClass('disabled'))
		{
			return false;
		} else {
			if ($pag_sape < 2)
			{
				$('ul.pagi_tips li').removeClass('disabled')
				$pag_sape++;
				$('ul.tips_and_tricks').animate({
					left: '-=205'
				}, 1000, function() {
					// Animation complete.
				});
			}
		}
		return false;
	});


	$('div.masina').hover(function(){
		$(this).addClass('masina_hover');
	},function(){
		$(this).removeClass('masina_hover');
	});
/*
	$("input[type=file]").filestyle({ 
		 image: "-res/img/btn_adauga_poza_ta.png",
		 imageheight : 46,
		 imagewidth : 182,
		 width : 182
	 });
*/
	$('input[type=file]').each(function(){
		$(this).addClass('file').addClass('hidden');
		$(this).parent().append($('<div class="fakefile" />').append($('<input type="text" />').attr('id',$(this).attr('id')+'__fake')).append($('<img src="-res/img/btn_adauga_poza_ta.png" alt="" />')));
		$(this).bind('change', function() {
			$('#'+$(this).attr('id')+'__fake').val($(this).val());;
		});
		$(this).bind('mouseout', function() {
			$('#'+$(this).attr('id')+'__fake').val($(this).val());;
		});
	});


	$('#msg_success.retete span.ok').click(function(){
		window.location = 'http://www.institutulderelaxare.ro/masina-de-paine/retete/users/';
	});

	$('#msg_success.tips span.ok').click(function(){
		window.location = 'http://www.institutulderelaxare.ro/masina-de-paine/tips-and-tricks/users/';
	});

	$('#msg_success.concurs span.ok').click(function(){
		window.location = 'http://www.institutulderelaxare.ro/masina-de-paine/concurs/galerie/';
	});

	$('#msg_success.gift span.ok').click(function(){
		window.location = 'http://www.institutulderelaxare.ro/masina-de-paine/concurs/galerie/';
	});

});
