function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-150;//150 is half popup's height
	if (popUpDivVar != '')
	popUpDiv.style.top = '135px'; //popUpDiv_height + 'px';
	popUpDiv.style.position = 'fixed'; //popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-350;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}
function popup(windowname) {
	var params = {};
	if ($('blanket').style.display == 'none') {
		params['state'] = 'open';
	} else {
		params['state']  = 'shut';
	}
	new Ajax.Request('/activity/record_where_next_popup', { parameters: params });
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);		
}

$jq(document).ready(function() {
	
	$jq('.see-full-review').click(function(){
		var review_id = $jq(this).parent().parent().attr('id').replace(/short-review-/, '');
		$jq('#short-review-' + review_id).hide();
		$jq('#full-review-' + review_id).show();
		return false;
	});
	
	$jq('.see-full-review').hover(
	function() {
		$jq(this).find('span').addClass('hovered');
	},
	function() {
		$jq(this).find('span').removeClass('hovered');
	});
	
	$jq('.see-short-review').hover(
	function() {
		$jq(this).find('span').addClass('hovered');
	},
	function() {
		$jq(this).find('span').removeClass('hovered');
	});

	$jq('.see-short-review').click(function(){
		var review_id = $jq(this).parent().attr('id').replace(/full-review-/, '');
		$jq('#full-review-' + review_id).hide();
		$jq('#short-review-' + review_id).show();
		return false;
	});
	
	$jq('.see-review-cate').click(function(){	
		$jq(this).parent().parent().find('.review-cate').toggleClass('hidden');
		return false;
	});
	
	var popRateNotHovered = true;
	$jq(".show-rates-btn").hoverIntent(
		function() {
			var popRate = $jq(this).parent().parent().parent().parent().parent().find('.pop-rate');
			popRate.css({'margin-left':'105px', 'margin-top':'10px'})
			popRate.show();
		},
		function() {
			var popRate = $jq(this).parent().parent().parent().parent().parent().find('.pop-rate');
			setTimeout( function() {if (popRateNotHovered) {popRate.fadeOut(100)};}, 600);				
		}
	);

	$jq('.pop-rate').hover(function() {popRateNotHovered = false;},	function() {
		popRateNotHovered = true; $jq(this).fadeOut(300);
	});
	
	$jq('#select-review-product-type').change(function() {
		window.location = $jq(this).val();
	});		
});

