var $j = jQuery.noConflict();
$j(document).ready(function(){	
	/* \ ################################################################################# \ */
	/*  \ ################################################################################# \ */
	/*   \ ################################################################################# \ */
	
	var jCheck = $j('.jCheck').val();
	
	if(jCheck=="msg"){
		var fixCheck = true;
		$j('#oben').css('height', '210px');
		$j('#unten').css('border', 'none');
		$j('#unten').css('height', '130px');
		$j('#newsletterbox').css('opacity', '1.0');
		$j('#newsletterbox').css('height', '190px');
		$j('#newsletterbox').css('bottom', '100px');
		
	} else if(jCheck=="empty") {
		var fixCheck = false;
		$j('#newsletterbox').css('opacity', '0.0');
	}
	
	
	$j('#umschlag').mouseover(function(){
		if(fixCheck===false){
			$j('#oben').animate({
				height: 210
			}, function(){
				$j('#unten').css('border', 'none');
				$j('#unten').css('height', '130px');
				$j('#newsletterbox').animate({
					opacity : 1.0,
					height: 190,
					bottom : 100
				}, function(){
					fixCheck = true;
				});
			});
		}
	});
	
	
	$j('#content_top, #menu, #left, #sitecontent_bottom, #content_bottom, h1').mouseover(function(){
		if(fixCheck===true){
			$j('#newsletterbox').animate({
				opacity : 0.0,
				height : 0,
				bottom : 0
			}, function(){
				$j('#unten').css('borderTop', '1px solid #E2E2E2');
				$j('#unten').css('height', '129px');
				$j('#oben').animate({
					height: 0
				}, function(){
					fixCheck = false;
				});
			});
		} 
	});
	
	
	$j(".gewinnspiel input:radio").change(function(){
		var feld = $j(this).attr('name');
		var buchstabe = $j(this).val();
		$j('.loesungsfeld[name=l'+feld+']').val(buchstabe);
	});
	
	
	$j('.greystar').mouseover(function(){
		var bew = $j(this).attr('title');
		$j('.greystar, .redstar').each(function(){
			var bewstar = $j(this).attr('title');
			if(bewstar<=bew){
				$j(this).addClass('redstar');
				$j(this).removeClass('greystar');
			} else if(bewstar>bew){
				$j(this).addClass('greystar');
				$j(this).removeClass('redstar');
			}
		});
	});
	
	$j('.bewertungssterne').mouseout(function(){
		$j('.redstar').each(function(){
			$j(this).addClass('greystar');
			$j(this).removeClass('redstar');
		});
	});
	
	
	function ajaxRating(imgid, points){
		postvars = 'ic_id='+imgid+'&points='+points;
		$j.ajax({
			url: "imgbewertung.php",
			type: "GET",
			data: postvars,
			success: function (data) {
				$j('.bewertungssterne').addClass('info');
				$j('.info').removeClass('bewertungssterne');
				
				var content = $j('.info').html();
				$j('.info').html(data);

				updatePoints(imgid);
			}
		});
	}
	
	function updatePoints(imgid){
		postvars = 'ic_id='+imgid;
		$j.ajax({
			url: "punkteupdate.php",
			type: "GET",
			data: postvars,
			success: function (data) {
				var content = $j('.bewertungsausgabe').html();
				$j('.bewertungsausgabe').html(data);
			}
		});
	}
	
	$j('.greystar').click(function(){
		var imageid = $j('.ratingimg').attr('alt');
		var points = $j(this).attr('title');
		ajaxRating(imageid, points);
	});
	
	
	/*   / ################################################################################# / */
	/*  / ################################################################################# / */
	/* / ################################################################################# / */
});
