var $j = jQuery.noConflict();

var pause = false;

$j(document).ready(function() {
	
	$j(".ordpussel").click(function() {
		
		
		window.open( "http://redikod.com/ord", "gameWindow", 
"status = 1, height = 640, width = 960, resizable = 0" );
		
		
	
	});

	$j(".fancyboxhref").fancybox();
	
	$j(".galleryitem").hover(function() {
		pause = true;
	}, 
	function () {
		pause = false;
	});
	
	$j(".galleryitem").click(function() {
		pause = false;
		swapImages();
		pause = true;
	});
	
	$j(".metric_external").click(function() {
		
		var id = $j(this).attr("rel");
		var uid = $j(this).attr("rel2");
		
		$j.ajax({
			type: "GET",
			url: "http://nordicgameportal.com/ajaxpages.php?page=metricsext&gid="+id+"&uid="+uid,
			success: function(msg) {
				
			}			
		});

	});
	
	

	
	
	$j("#clickme").click(function(){
	
		var divOffset = $j('#spotanim').offset().top;
	    var pOffset = $j('#spotanim p:eq(1)').offset().top;
	    var pScroll = pOffset - divOffset;
	
		$j("#spotanim").animate({scrollTop:"+=" + pScroll + "px"},1000, 'linear');
		
		return false;
		
	
	});
	
	$j("#developergamelist").change(function() {
	
		var id = $j("#developergamelist option:selected").val();
		$j.ajax({
			type: "GET",
			url: "http://nordicgameportal.com/ajaxpages.php?page=metrics&gid="+id,
			success: function(msg) {
				$j("#gamestats").val(msg);
			}			
		});
	
	
	
	});
	
	setInterval('swapImages()', 5000);
	
	$j("#closeexplicit").click(function() {
	
		$j.ajax({
			type: "GET",
			url: "http://nordicgameportal.com/ajaxpages.php?page=explicit",
			success: function(msg) {

			}			
			});
	
		$j("#explicit").hide();
		return false;
	
	});
	
	$j("#pageinate > *").live("click", function(){
		
		$j("#ppage").val($j(this).attr("href"));
		$j(".ajaxgames").trigger("change");
		return false;
		
	
	});
	
	$j.ajax({
			   type: "POST",
			   url: "ajaxpages.php?page=gamelist",
			   data: ({'searchhidden':$j("#searchhidden").val(), 'age':$j("#age").val(),'price':$j("#hidden_price").val(),'genre':$j("#genre").val() }),
			   success: function(msg){
			     $j(".gamelist").html(msg);
			   }
		});
	
	$j(".ajaxgames").change(function() {
	
		
   
		var url = "ajaxpages.php?page=gamelist";
		var data = "";
		
		var countries = $j(":checkbox[name='country[]']:checked").map(function(i,n) {
        return $j(n).val();
    	}).get(); 
    	
    	var genre = $j("#genre").val();
		var price = $j("#hidden_price").val();
		
		if($j("#ppage").val()> 0)
			url += "&p="+$j("#ppage").val();
		
		
		$j.ajax({
			   type: "POST",
			   url: url,
			   data: ({'country[]':countries, 'genre':genre, 'age':$j("#age").val(),'price':price }),
			   success: function(msg){
			   $j("#ppage").val("0");
			     $j(".gamelist").html(msg);
			   }
		});
			
	
	
	
	});
	
	
});

function swapImages(){
      var $active = $j('.galleryitem.active');
      var $next = ($j('.galleryitem.active').next().length > 0) ? $j('.galleryitem.active').next() : $j('.galleryitem:first');
      
      if(!pause)
	  {   
	      $next.fadeIn("slow").addClass('active');
	      $active.fadeOut("slow", function(){
	      $active.removeClass('active');
	      });
	  }
    }

function doPopupPreview(pSchool, pLang) 
{
	if(pSchool == pLang)
		pLang = "";
	
	if(pSchool == null)
		pSchool = "";
		
	i = document.stats.dev_games.selectedIndex;
	gameid = document.stats.dev_games.options[i].value;
	
	newwin = window.open('/popuppreview.php?gid=' + gameid + pSchool +pLang, 'preview', 'scrollbars,status,width=400,height=600');
	
	
	
  newwin.focus();
  return true;
}



function imposeMaxLength(Object, MaxLen)
{
	if (Object.value.length >= MaxLen) 
	{ 
		Object.value = Object.value.substr(0,MaxLen-1); 
		Object.focus(); 
        return false; 
    } 

}

function doPopup() 
{
  newwin = window.open('', 'paywin', 'scrollbars,status,width=550,height=600');
  newwin.focus();
  return true;
}



