$(document).ready(function(){

	//rotation speed and timer
	var speed = 10000;
	var run = setInterval('rotate()', speed);	
	
	//grab the width and calculate left value
	var item_width = $('#slides li').outerWidth(); 
	var left_value = item_width * (-1); 
        
    //move the last item before first item, just in case user click prev button
	$('#slides li:first').before($('#slides li:last'));
	
	//set the default item to the correct position 
	$('#slides ul').css({'left' : left_value});

    //if user clicked on prev button
	$('#prev').click(function() {

		//get the right position            
		var left_indent = parseInt($('#slides ul').css('left')) + item_width;

		//slide the item            
		$('#slides ul:not(:animated)').animate({'left' : left_indent}, 200,function(){    

            //move the last item and put it as first item            	
			$('#slides li:first').before($('#slides li:last'));           

			//set the default item to correct position
			$('#slides ul').css({'left' : left_value});
		
		});

		//cancel the link behavior            
		return false;
            
	});

 
    //if user clicked on next button
	$('#next').click(function() {
		
		//get the right position
		var left_indent = parseInt($('#slides ul').css('left')) - item_width;
		
		//slide the item
		$('#slides ul:not(:animated)').animate({'left' : left_indent}, 200, function () {
            
            //move the first item and put it as last item
			$('#slides li:last').after($('#slides li:first'));                 	
			
			//set the default item to correct position
			$('#slides ul').css({'left' : left_value});
		
		});
		         
		//cancel the link behavior
		return false;
		
	});        
	
	//if mouse hover, pause the auto rotation, otherwise rotate it
	$('#slides').hover(
		
		function() {
			clearInterval(run);
		}, 
		function() {
			run = setInterval('rotate()', speed);	
		}
	); 


    $(function() {
        $('a.lightbox').lightBox();
    });


    $('.hp_more').toggle(function() {
        $(this).html('[hide]');
        $(this).parent().prev('.hp_more_block').css('display','block');
        return false;

    }, function() {
        $(this).html('[show more]');
        $(this).parent().prev('.hp_more_block').css('display','none');
        return false;

    });

    $('.expand').toggle(function() {
        $(this).html('[hide]');
        $(this).parent().prev('.expand_block').css('display','block');
        return false;

    }, function() {
        $(this).html('Show more');
        $(this).parent().prev('.expand_block').css('display','none');
        return false;

    });

    $('a#linkus').click(function() {
        $('#linkus_block').css('display', 'block');
        $('a#linkus').css('display', 'none');
        return false;
    });

    $('a#continue').click(function() {
        $('#linkus_block').css('display', 'none');
        $('#linkus_form').css('display', 'block');
        return false;
    })

    $('#linkus_form form').submit(function() {
        if ($('#form_name').val() == '' || $('#form_link').val() == '') {
         alert('Please fill in your link and e-mail.')
         return false;
        }


        $.post('/europa-international/link.php', $("#linkus_form form").serialize(), function(data) {
            $('#linkus_form').html(data);
        });

        return false;

    });         

});           


//a simple function to click next link
//a timer will call this function, and the rotation will begin :)  
function rotate() {
	$('#next').click();
}

