var global_images ;
a_movement = 0 ;



function checkErr() {
	$ ( 'photo_result' ).innerHTML = "" ;
	auxstr = $( 'upload_target' ).contentWindow.document.getElementById ( 'errors_text' ).innerHTML ;
	if( !auxstr.blank() ) {
		$( 'messages' ).toggle() ;
		$( 'messages_text' ).innerHTML= auxstr  ;
	}
	//alert( "DA" ) ;
}






	Shadowbox.loadSkin('classic', '/scripts/library/shadowbox/src/skin')     ;
	Shadowbox.loadLanguage('en', '/scripts/library/shadowbox/src/lang')   ;
	Shadowbox.loadPlayer(['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'], '/scripts/library/shadowbox/src/player');


	window.onmousemove = getMouseCoordinates ;

	var xi ;
	var yi ;

	function createLI( images , photos_tags ) {
		lista = "" ;
		for( i = 0 ; i < images.length ; i++ ) {

			true_s_image = "/" + images[ i ][ 'im_path' ] + "s2" + images[ i ][ 'im_name' ] ;
			true_b_image = "/" + images[ i ][ 'im_path' ] + "b"  + images[ i ][ 'im_name' ] ;
			lista += "<li id = \"li" + images[ i ][ 'im_id' ] + "\" >" ;
			lista += '<a id = "a' + i + '"  href="' + true_b_image + '" title = "' + photos_tags[ i ] + '">' ;
			lista += '<img  border = "0" alt="' + photos_tags[ i ] + '" src="' + true_s_image + '" /></a>' ;
			lista += '</li> ' ;

		}
		return lista ;

	}

	a_movement = 0 ;
	i_div_length = 475 ;
	image_div_nr= 4  ;//i_div_length=4;
	image_count = image_div_nr;

	function iniTiaLize() {
		a = new String( $( 'errors' ).innerHTML ) ;
		if( ! a.blank() ) {
			
		}
		a_movement = 0 ;
		i_div_length = 475 ;
		image_div_nr= 4  ;
		image_count = image_div_nr ;
		Shadowbox.init({
			skipSetup: true
		}) ;

		//galerry

		
		
		//end galerry





	};

	var my_gal = new Array() ;

	function addToShadowbox( id , gname ) {
		Shadowbox.setup( $("a"+id) , { gallery: gname } ) ;
		var imgss = {
			player: 'img',
			content: $( "a" + id ).href
		} ;
		my_gal[ my_gal.length ] = imgss ;  //alert( $( "a" + id ).href ) ;
	}



	function photo_result() {
		$( 'photo_result' ).innerHTML  =   "" ;
	}

	var cur_gal ;

	function addToShadowboxAll() {
		my_gal = new Array() ;
		Shadowbox.clearCache() ;
		var date = new Date() ;
		var random_nr = date.getTime() ;
		cur_gal = random_nr ;
		var galery_name = "galery" + random_nr     ;    
 		for( i = 0 ; i < image_nr ; i++ )
		addToShadowbox( i , galery_name )      ;
	}



	function complete_div( bigpig , medpig ) {
		$( 'container' ).show() ;
		curent_random = image_nr ;
		image_nr++ ;
		strdiv = $( 'ulImage' ).innerHTML   ;
		strdiv ='<li><a id = "a' + curent_random + '"   href="'+bigpig+'"><img hspace = "0" border = "0"   src="' + medpig + '"  /></a></li>'  + strdiv  ;
		$( 'ulImage' ).innerHTML = strdiv ;
		addToShadowboxAll() ;
	}





	function moveToFirst() {

		//	alert( image_nr ) ; alert( image_count ) ;

		if( a_movement ) return ;
		if(   image_count   < image_div_nr ) {
			moveToPrevious() ; return ;
		}


		else {
			a_movement = 1 ;
			new Effect.Move('imageBoxInside',
			{ x: 122 *(image_count - image_div_nr    )    , y: 0, transition: Effect.Transitions.sinoidal , afterFinish :function(){
				a_movement = 0 ;
			}
			} ) ;


			image_count = 0 ;

		}

		image_count = image_div_nr ;

	}

	function moveToLast() {

		// 		 	alert( image_nr ) ; alert( image_count ) ;

		if( a_movement ) return ;

		if(    (  image_nr-image_count  )    < image_div_nr ) {

			moveToNext() ; return ;

		}


		else {

			new Effect.Move('imageBoxInside',
			{ x: - 122 * ( image_nr - image_count   )      , y: 0, transition: Effect.Transitions.sinoidal , afterFinish :function(){
				a_movement = 0 ;
			}
			} ) ;


			image_count = image_nr ;

		}



	}




	function moveToPrevious()
	{

		x_move = i_div_length ;
		if ( a_movement ) return ;
		a_movement = 1 ;
		if( image_count == image_div_nr ) { a_movement = 0 ; return  ; }
		a_movement = 1 ;
		if ( image_count - image_div_nr <= image_div_nr ) {

			new Effect.Move('imageBoxInside',
			{ x: 122*( image_count - image_div_nr ) , y: 0, transition: Effect.Transitions.sinoidal , afterFinish :function(){
				a_movement = 0 ;
			}
			} ) ;
			image_count = image_div_nr ;
			return ;


		}

		else image_count-= image_div_nr ;
		new Effect.Move( 'imageBoxInside',
		{ x: x_move , y: 0, transition: Effect.Transitions.sinoidal , afterFinish :function() {
			//alert ( image_count ) ;
			a_movement = 0 ;
		} }) ;
		$( 'imageBox' ).style.overflow = "hidden" ;


	}

	function moveToNext()
	{
		x_move = i_div_length ;
		if ( a_movement ) return ;
		a_movement = 1 ;
		if ( image_count == image_nr ) { a_movement = 0 ;  return  ; }
		if ( image_count >= image_nr - image_div_nr ) {
			new Effect.Move('imageBoxInside',
			{ x: 122*(image_count-image_nr ) , y: 0, transition: Effect.Transitions.sinoidal , afterFinish :function(){
				a_movement = 0 ; }
			} ) ;
			image_count = image_nr ;
			a_movement = 1 ;   return ;
		}
		else image_count += image_div_nr ;
		new Effect.Move('imageBoxInside',
		{ x: -x_move, y: 0, transition: Effect.Transitions.sinoidal , afterFinish :function() {
			//alert( image_count ) ; alert( image_nr ) ;
			a_movement = 0 ; }  }); return  ;


	}


