var add_iapp_rotate_screenshots, add_iapp_download_crack;
var _add_iapp_itunes_urls = {};

( function($) {
	$(document)
			.ready(
					function() {
					  	add_iapp_rotate_screenshots(jQuery("ul.jcarousel-skin-tango"));
						$(".jcarousel-prev-horizontal").css('top', (($("ul.jcarousel-list-horizontal").height()/2)-10)+'px');
						$(".jcarousel-next-horizontal").css('top', (($("ul.jcarousel-list-horizontal").height()/2)-10)+'px');
					});

	function add_iapp_init_callback(carousel) {
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});

		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});

		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover( function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	}

	add_iapp_rotate_screenshots = function(parent) {
		if ($.jcarousel) {
			$(parent).jcarousel( {
				auto : 2,
				scroll : 1,
				wrap : 'last',
				initCallback : add_iapp_init_callback
			});
		}
	}
	
	add_iapp_download_crack = function(app_id) {
		if (_add_iapp_itunes_urls && _add_iapp_itunes_urls[app_id]) {
			window.location = _add_iapp_itunes_urls[app_id];
		} else {
			alert('We are unable to find the tested app application. Please report as a broken link');
		}
	}
	

	add_iapp_report_link = function (meta_id) {
		$.get('', {action: 'report_link', meta_id: meta_id, type: 'ajax'}, 
			  function (data) {
				alert(_add_iapp_err_link_reported);
			  }
		);
	}
	
})(jQuery);
