$(document).ready(function() { 	
	
	resize_bows = function(){
		$('#footer').css({'left' : '0'});
		$(window).scroll(function () { 
			var p = $(document);
			var dudu = p.scrollLeft();
			if (dudu == 0)
			{
				$('#footer').css({'left' : '0'})
			}
			else
			{
				$('#footer').css({'left' : '-' + dudu + 'px'})
			}
		});
	}

	resize_bows();

	$("a[rel=gallery_photo]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: showPopupTitle,
		'padding'			: 0,
		'onComplete'		: disableRightClick
	});
	
	var url_vars = getUrlVars();
	
	if ( ( typeof( url_vars['id'] ) != 'undefined' ) && ( url_vars['id'] > 0 ) ) {
		
		$( 'a#item_' + url_vars['id'] ).trigger( 'click' );
	}
	
	disableRightClick();
});

function disableRightClick()
{
	$('img').bind('contextmenu', function(e){
	    return false;
	});
}

var title_to_return;

function showPopupTitle(title, currentArray, currentIndex, currentOpts){
	
	title_to_return = null;
	
	var data = $( '#popup_title_' + currentIndex ).html().split( '-' );
	
	$.ajax( {
		url: base_url + index_page + cur_lang + '/' + data[0] + '/title',
		type: 'post',
		dataType: 'html',
		data: { item_id : data[1] },
		success: function( response ) {
			
			title_to_return = response;
		}
	} );
	
	if ( title_to_return == null ) {
		
		setTimeout( 'returnTitle()', 1500 );
	} else {
		
		return $( '#fancybox-title-over' ).html( title_to_return );
	}
	
	return '<span id="fancybox-title-over"></span>';
}

function returnTitle() {
	
	return $( '#fancybox-title-over' ).html( title_to_return );
}

function getUrlVars() {
	
    var vars = [], hash;
    var hashes = window.location.href.slice( window.location.href.indexOf( '?' ) + 1 ).split( '&' );
    
    for( var i = 0; i < hashes.length; i++ ) {
    	
        hash = hashes[ i ].split( '=' );
        vars.push( hash[0] );
        vars[ hash[0] ] = hash[1];
    }
    
    return vars;
}
