var tain_session_id;


/* Vi-clone */


/* Vi-clone */

$(document).ready(function() {	
	if($('#clipsright')){
		$('#clipsright').load('/rightsidebar.php');
	} 
	if($('#clipsbottom')){
		$('#clipsbottom').load('/bottomlist.php');
		
	} 

	$('#clip-revolver').cycle({ 
	    fx:     'scrollHorz', 
	    prev:   '#prev', 
	    next:   '#next', 
	    cleartypeNoBg: false,
	    timeout: 0 
	});
	
	$("#category").change(function () {
		str = $(this).val();   
        $('#clipsright').load('/rightsidebar.php?id='+str);;
      });
	$(".full #category").change(function () {
		str = $(this).val();   
        $('#clipsbottom').load('/bottomlist.php?id='+str);;
        $(".full #category option:selected").each(function () {
            label= $(this).text() ;
          });

        $('#category_label').html(label);
      });
	$('.pages-clip').live('click', function(e) {
		e.preventDefault();
		$f('big_player', {src: "/swf/flowplayer-3.2.7.swf", wmode: 'opaque'},{
		    clip: {
		        url: $(this).attr('href')
		    },
		    onLoad: function(){
		      //   alert("player loaded.");
		    }
		});				
		$('#clip-title').html($(this).attr('title'));
		$('#bigbuylink').attr('href','/clips/payment-options/'+$(this).attr('clipid')+'/')  ;
	});
	
	
	
	
	$('.revolver-clip').hover(function () {
		$(this).find('.description').show();

	},function(){
		$(this).find('.description').hide();
	}); 
	/*
	$(".clip").hover(
	  function () {
	    $(this).append($("<div class=description> ***</div>"));
	  }, 
	  function () {
	    $(this).find("div:last").remove();
	  }
	);
*/
	
	$(function(){
        $("#blink").show();
        setTimeout(function(){$("#blink").show();setInterval(function(){$("#blink").fadeToggle('fast');},700)},700);                       
	});
		
	$('a#login-button, #menu-login a').live('click', function(e) {
		e.preventDefault();
		if($('#the-game')){
			$('#the-game').css('visibility','hidden');
		}
		if($('#big_player')){
			$('#big_player').css('visibility','hidden');
		}


		$.fancybox({
			'href': $(this).attr('href'),
			'hideOnContentClick': false,
			'overlayOpacity': 0.7,
			'overlayColor': '#000',
			'onComplete': function() {
				if ($('#username')) {
					$('#username').focus();
				}
			},
			'onClosed': function(){
				if($('#the-game')){
					$('#the-game').css('visibility','visible');
				}
				if($('#big_player')){
					$('#big_player').css('visibility','visible');
				}
			}
		});
		
		
	});
	
	$('a#register-button, #menu-register a, a#big-join-button, a#btn-big-yellow, a#tos, a.tos').live('click', function(e) {
		e.preventDefault();
		if($('#the-game')){
			$('#the-game').css('visibility','hidden');
		}
		if($('#big_player')){
			$('#big_player').css('visibility','hidden');
		}
		$.fancybox({
			'href': $(this).attr('href'),
			'hideOnContentClick': false,
			'overlayOpacity': 0.7,
			'overlayColor': '#000',
			'onComplete': function() {
				if ($('#username')) {
					$('#username').focus();
				}
			},
			'onClosed': function(){
				if($('#the-game')){
					$('#the-game').css('visibility','visible');
				}
				if($('#big_player')){
					$('#big_player').css('visibility','visible');
				}
			}
		});
	});
	
/*	$('a#logout-button').live('click', function(event) {
		// $.fancybox.showActivity();
		
		event.preventDefault();
		
		var href = $(event.currentTarget).attr('href');
		tain_session_id = null;
		
		
		$(location).attr('href',href);
	//	$.fancybox.hideActivity();
	});*/
	
	$('a.buyable-clip, a.betable-clip, .fancybox').live('click', function(e) {
		e.preventDefault();
		if($('#the-game')){
			$('#the-game').css('visibility','hidden');
		}
		if($('#big_player')){
			$('#big_player').css('visibility','hidden');
		}
		
		$.fancybox({
			'href': $(this).attr('href'),
			'hideOnContentClick': false,
			'overlayOpacity': 0.7,
			'overlayColor': '#000',
			'onClosed': function(){
				if($('#the-game')){
					$('#the-game').css('visibility','visible');
				}
				if($('#big_player')){
					$('#big_player').css('visibility','visible');
				}
			}
		});
	});
	
	$('#game-changer').superfish({
		'animation':	{opacity: 'show', height: 'show'},
		'speed':		'fast'
	});
	
	// gör så tumnaglarna spelar upp en animation...
	$('div.thumb').hover(function(event) {
		var id = $(event.currentTarget).attr('id');
		
		change_thumbnail = setInterval('changepic(\'' + id + '\')', 500);
	}, function(event) {
		clearInterval(change_thumbnail);
		
		//var first_pic = $(event.currentTarget).parent('li').metadata({'type':'elem', 'name':'script'}).bilder[0];
		
		$(event.currentTarget).css('background-position', '0px');
	});
	
	$('a#forgot-password').live('click', function(e) {
		e.preventDefault();		
		$.fancybox({
			'href': $(this).attr('href'),
			'hideOnContentClick': false,
			'overlayOpacity': 0.7,
			'overlayColor': '#000',
			'onComplete': function() {				
			},
			'onClosed': function(){				
			}
		});
		
		
	});
});

function changepic(id) {
	var x_pos = parseInt($('#' + id).css('background-position'));
	
	x_pos -= 161;
	
	if (x_pos < -1449) {
		x_pos = 0;
	}
	
	$('#' + id).css('background-position', x_pos + 'px');
}

