document.write('<script type="text/javascript" src="/func/jquery.MetaData.js"></script>');
document.write('<script type="text/javascript" src="/func/jquery.ui.js"></script>');
document.write('<script type="text/javascript" src="/func/jquery.livequery.js"></script>');
document.write('<script type="text/javascript" src="/func/swfobject.js"></script>');
document.write('<script type="text/javascript" src="/func/jquery.rating.js"></script>');

var interval_counter, thour, tmin, ctitle, offset;

function play_video (target, id)
{
	var player;
	
	switch (target)
	{
		case 'xvideos':
		
		player = 'http://static.xvideos.com/swf/flv_player_site_v4.swf';
		
		var flashvars = 
		{
			id_video: id
		};
		
		var params = 
		{
			movie: 'http://static.xvideos.com/swf/flv_player_site_v4.swf',
			allowNetworking: 'always',
            allowScriptAccess: 'always'
		};
		
		break;
		
		case 'pornhub':
		
		player = 'http://cdn-www.pornhub.com/flash/embed_player_v1.3.swf';
		
		var flashvars = 
		{
			options: 'http://www.pornhub.com/embed_player.php?id=' + id
		};
		
		var params = 
		{
			allowNetworking: 'always',
            allowScriptAccess: 'always'
		};		
		
		
		break;
		
		case 'redtube':
		
		player = 'http://embed.redtube.com/player/?id=' + id + '&style=redtube';
		
		var flashvars = 
		{
			id: id,
			style: 'redtube',
			options: 'http://www.pornhub.com/embed_player.php?id=' + id
		};
		
		var params = 
		{
			movie: 'http://embed.redtube.com/player/',
			allowNetworking: 'internal'
		};		
		
		
		break;
        
        case 'youporn':
        
        player = 'http://static.youporn.com/r/20081115.1/player/seekable.swf';
        
        var flashvars =
        {
            file : encodeURIComponent('http://download.youporn.com/download/' + id + '?ll=1&xml=1'),
            type : 'xml',
            location : player,
            bufferlength : 3
        };
        
        var params =
        {
            allowNetworking: 'internal'
        };	

        break;
	}
		
	swfobject.embedSWF
	(
		player, 
		'embed', 
		'750', '580', 
		'9.0.0',
		'', 
		flashvars, params
	);
}

function validate (id)
{		
	if ($(id).attr('name') == 'passwd2')
	{
		var value = $('#fpasswd1').val() + $('#fpasswd2').val();
	}
	else
	{
		var value = $(id).val();
	}
	
	$.ajax
	({
		type: 'POST',
		url: '/register',
		data: 'validate=' + $(id).attr('name') + '&value=' + value,
		success: function (data)
		{				
			if (data != 1)
			{
				$(id).parent().find('.error').html(data);
			}
			else
			{
				$(id).parent().find('.error').html('');					
			}
		}
	});			
}

function adult_check (check)
{
	if (check != 1)
	{
		$('body').load('/intro.php');
	}
}

function unix_timestamp()
{
	return new Date().getTime();
}


function time_counter ()
{	
	var dhour, dsec, dmin = 0;
	
	var time = new Date();
	time.setTime(unix_timestamp() + offset - 5000);
	
	hour = time.getHours();
	minute = time.getMinutes();
	
	dhour = thour - hour;
	dmin = tmin - minute;	
	dsec = 59 - time.getSeconds();
	
	if (dmin < 0 && dhour > 0)
	{
		dmin = 59 - minute + tmin;
		dhour--;
	}
				
	if (dhour >= 0 && dmin >= 0)
	{			
		if (dsec < 10)
			dsec = '0' + dsec;
					
		if (dmin < 10)
			dmin = '0' + dmin;
			
		$('#next_content').html('Nowy film <strong>' + ctitle + '</strong> już za ' + dhour + ':' + dmin + ':' + dsec);
		return 0;
	}
	else
	{
        if (dhour > 0)
        {
            $('#next_content').html('Dodano nowy film! <strong>' + ctitle + '</strong>');
        }
		clearInterval(interval_counter);
		return 0;
	}
}

function time_counter_init (time1, time2, title)
{
	offset = (time1 * 1000) - unix_timestamp();
	
	var time = new Date();
	time.setTime(time2 * 1000);

	thour = time.getHours();
	tmin = time.getMinutes();
	
	ctitle = title;
	
	time_counter();
	interval_counter = setInterval(function() { time_counter(); }, 1000);
}

$(document).ready(function()
{
	var interval_id;
	
	$('.content img').mouseenter(function()
	{
		var id = $(this);
		var i = 2, max = 100;
		var hash = $(this).attr('class');
		var thumb = new Image;
		
		thumb.src = 'http://content.pornomax.pl/' + hash + '/' + i + '.jpg';	
		
		interval_id = setInterval(function ()
		{
			if (max == 100)
			{								
				if (thumb.width == 0)
				{
					max = i - 1;
                    i = 1;
				}
				else
				{
					thumb.src = 'http://content.pornomax.pl/' + hash + '/' + (i + 1) + '.jpg';
				}
			}
			
			$(id).attr('src', 'http://content.pornomax.pl/' + hash + '/' + i + '.jpg');
			
			i = (i < max) ? i + 1 : 1;
			
		}, 1000);
	});
	
	$('.content img').mouseleave(function()
	{
		clearInterval(interval_id);
	});
	
	$('.validate').blur(function()
	{
		validate($(this));
	});
	
	$('.miniStar').rating();
	$('.miniStar').rating('disable');
});
