var border_img_class = 'border_img';
var right_arrow_id = 'arrowR';
var left_arrow_id = 'arrowL';
var sliding_bar_id = 'list_of_images';
var dfull = 'full';

/***************************************************/
/* DO NOT EDIT AFTER THIS LINE
/***************************************************/

/*
 * @Don't let every one see the the errors
*/

$(window).error(function () {
	if(window.location.hostname == "localhost") {
		return true;
	} else {
		return false;
	}
});

$(document).ready(function () {

	/* ##############################
	### Make the Rolling Bar Role =P
	############################## */

	// Add to the sliding bar a div width the necessary width
	var imgSwidth = $('#'+sliding_bar_id+' img').width();
	var inslide_width = $('#'+sliding_bar_id+' img').size() * 220;

	var slidbar = $('#'+sliding_bar_id);
	slidbar.html('<div style="height: 136px; width: '+inslide_width+'px;">'+slidbar.html()+'</div>');

	var int;
	var int2;

	// When the user press the left arrow start the cool thing
	$('#'+left_arrow_id).mouseover(function () {
		var rep = function () {
			var current = slidbar.scrollLeft();
			var maxwidth = current+1;
			slidbar.scrollLeft(current-2);

			if(current == 0) {
				clearInterval(int);
			}
		}

		int = setInterval(rep, 1);

	// When the user stoped pressing the arrow stop it
	}).mouseout(function () {

		clearInterval(int);

	});

	// When the user press the right arrow start the cool thing
	$('#'+right_arrow_id).mouseover(function () {

		var rep = function () {
			var current = slidbar.scrollLeft();
			slidbar.scrollLeft(current+2);

			if(current == slidbar.scrollLeft) {
				clearInterval(int2);
			}
		}

		int2 = setInterval(rep, 1);

	// When the user stoped pressing the arrow stop it
	}).mouseout(function () {

		clearInterval(int2);

	});

	/* ##############################
	### When the user presses a thumbnail
	### show the big one
	############################## */

	$('#'+sliding_bar_id+' img').click(function () {

		var src = $('#' + sliding_bar_id + ' img:eq('+ $('#'+sliding_bar_id+' img').index(this) + ')').attr('src');

		var getFilename = src.split('/');
		getFilename = getFilename[getFilename.length-1];

		$('#'+dfull).slideDown("slow", function () {
			$('#'+dfull+' img').fadeOut("fast", function () {
				$(this).attr({
					src: "/full/"+getFilename
				});
			});

			$('#'+dfull+' img').load(function () {

				var s_width = $(this).width();
				var s_height = $(this).height();
				var diff = s_width / 738;

				var bigImg = s_height / diff;
				$('#full .border_img .rc').height(bigImg);
				$('#full .border_img .cc').height(bigImg);
				$('#full .border_img .lc').height(bigImg);

				$('#full .border_img').width(746);
				$('#full .border_img .ct').width(738);
				$('#full .border_img .cc').width(738);
				$('#full .border_img .cb').width(738);

				$(this).width(738);
				$(this).fadeIn("fast");
			});
		});
	});

	/* ##############################
	### Sliding last articles box
	############################## */

	$(function () {
        // basic version is: $('div.demo marquee').marquee() - but we're doing some sexy extras

        $('.roller marquee').marquee('pointer').mouseover(function () {
            $(this).trigger('stop');
        }).mouseout(function () {
            $(this).trigger('start');
        }).mousemove(function (event) {
            if ($(this).data('drag') == true) {
                this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
            }
        }).mousedown(function (event) {
            $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
        }).mouseup(function () {
            $(this).data('drag', false);
        });
    });
});

