// JavaScript Document

$(function(){
	BLOC_SCHIMB_REVIEW = false;
	
	$('a[href^="#"]').live('click',function(e){e.preventDefault();})
	
	$TITLU = $('h2','#win');
	$MESAJ = $('#continut-nonform > em','#win');
	$DATA = $('#continut-nonform > div#data','#win');
	$SALESMAN = $('#salesman','#win');
	
	_PAS = 0;
	
	
	$('#do-review').toggle(function(){
		BLOC_SCHIMB_REVIEW = true;
		if (_PAS == 2) {$('#bt-next').click(); return;}
		_PAS = 1;
		$('#win').hide();
		$('#continut-form1').show();
		$('#continut-form2').hide();
		$('#continut-nonform','#win').hide();
		

		$TITLU.html('<strong>' + 'Your Review' + '</strong>');
		
		$('#win').show();
		$("#win").css('width', 280);
		$('#tx_name').focus();
		pozitionare();

		
		$('#close').click(function(){ $('#do-review').click(); })
		
		},
		function(){	BLOC_SCHIMB_REVIEW = false; arata(); });
		
	$('#win').hover(
	function(){
		BLOC_SCHIMB_REVIEW = true;
		},
	function(){
		BLOC_SCHIMB_REVIEW = false;
		}
	);
	
	
	$('#bt-next').click(function(){
		//_PAS = 2; // de pus la loc cand se fac conditionarile
		$('#win').hide();
		$('#continut-form2').show();
		$('#continut-form1').hide();
		$('#continut-nonform','#win').hide();
		
		$TITLU.html('<strong>' + $('#tx_name').val() + ' - Your Review'  + '</strong>');
		$('#txx_salesman').text($('#tx_salesman').val());
		
		$('#win').show();
		$("#win").css('width', 400);
		$('#tx_message').focus();
		pozitionare();

		
		$('#close').click(function(){ $('#do-review').click(); arata(); })
		
		});
		
	
	$('#formular-review').submit(function(e){e.preventDefault();
		$tx_name = $('#tx_name').val();
		$tx_email = $('#tx_email').val();
		$tx_phone = $('#tx_phone').val();
		$tx_salesman = $('#tx_salesman').val();
		$tx_message = $('#tx_message').val();
		
		$.post("act/reviewsend.php", {txName : $tx_name, txEmail : $tx_email, txPhone : $tx_phone, txSalesman : $tx_salesman, txMessage : $tx_message},
			function(data){
				alert(data);
				$('#do-review').click(); arata(); 
			});
				
		});

	
	function arata(){
		
		$('#continut-form1').hide();
		$('#continut-form2').hide();
		$('#continut-nonform','#win').show();
		
		$("#loading").load('db.html',function(){

			NR_total = $('ul > li', this).length;
			if (NR_total<1) return; // ce sa cautam mai jos
			
			NR = Math.floor(Math.random()*(NR_total));
			//console.log(NR);
			
			
			$('#win').hide();
			$TITLU.html('<strong>' + $(this).eq(0).find('h1').eq(NR).text() + '</strong> said:');
			$MESAJ.html('').text( $(this).eq(0).find('p').eq(NR).text() );
			$DATA.html('<strong>Date:</strong> <span>' + $(this).eq(0).find('h2').eq(NR).text() + '</span>');
			var Salesman = $(this).eq(0).find('h3').eq(NR).text();
			if (Salesman != '') {
			$SALESMAN.append( $(this).eq(0).find('h3').eq(NR).text() );
				}else{$SALESMAN.remove();}
	
		
			$('#win').show();
			$("#win").css('width', 280);
			pozitionare();
		
			});
			
			$('#close').unbind('click');
			$('#close').click(function(){ $('#win').hide(); })
	} //$('#do-review').click();

	
	function pozitionare(){
		_top = -($(".continut","#win").height() + 33 + 30);
		_left = -($(".continut","#win").width() - 138);
		
		$("#win").css('marginTop', _top);
		$("#win").css('marginLeft', _left);
		}

		
	function randomSort(a,b) {
		// Get a random number between 0 and 10
		var temp = parseInt( Math.random()*NR_total );
		// Get 1 or 0, whether temp is odd or even
		var isOddOrEven = temp%2;
		// Get +1 or -1, whether temp greater or smaller than 5
		var isPosOrNeg = temp>1 ? 1 : -1;
		// Return -1, 0, or +1
		return( isOddOrEven*isPosOrNeg );
		}






/* BANNER TOP */
	//$('#banner').css('marginTop','-100px').show();
	$('#banner').animate({marginTop:5},1000);
	$('a','#banner').lightBox().click(function(e){e.preventDefault();})


	show_review = function(){
	arata();
	}
	
	});
