// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

//Check if we're in IE 6
var agt				= navigator.userAgent.toLowerCase();
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie6    = (is_ie && agt.indexOf("msie 6.")!=-1 );    


// Activate background image caching on IE6 to prevent image flicker
if (is_ie6) {
	document.execCommand('BackgroundImageCache', false, true);
}


var status = '0'; // initial status

var SHOW_ALL = '0';  	// shows menu, info and image
var SHOW_MENU = '1'; 	// shows menu and image
var SHOW_INFO = '2'; 	// shows info and image
var SHOW_IMAGE = '3'; // shows only the image

var current_picture = 1; //picture currently beeing display on the page, by default=1


function toggle_info() {

	var left_strip = $("left_strip"); // this is the menu div
	var info_strip = $('info_strip');
	//alert("image_slide_"+eval(current_picture))
	var image_slide = $("image_slide_"+eval(current_picture));
	var nav_strip = $("nav_strip");
	var nav_box = $("nav_box");

	switch (status){ 
   		case SHOW_ALL : // if SHOW_ALL and info button clicked hides info_srip and goes to state SHOW_MENU
   		    new Effect.Fade(info_strip);
   		    new Effect.Move(image_slide,{x:172, y: 0, mode: 'absolute'});
			status = SHOW_MENU;
      		break;
   		case SHOW_MENU :  // if SHOW_MENU and info button clicked shows info_srip and goes to state SHOW_ALL
   			new Effect.Move(image_slide,{x:447, y: 0, mode: 'absolute'}, {queue:'end'});
   		    new Effect.Appear(info_strip, {queue:'end'});
			status = SHOW_ALL;
      		break;
      	case SHOW_INFO :  // if SHOW_INFO and info button clicked hides info_srip and goes to state SHOW_IMAGE
   		    new Effect.Fade(info_strip, {queue: 'front'});
   		    new Effect.Move(image_slide,{x:10, y: 0, mode: 'absolute'}, {queue:'end'});
      		status = SHOW_IMAGE;
      		break;
      	case SHOW_IMAGE :  // if SHOW_IMAGE and info button clicked shows info_srip and goes to state SHOW_INFO
      		info_strip.style.left='45px';
   		    new Effect.Move(image_slide,{x:270, y: 0, mode: 'absolute'}, {queue:'end'});
   		    new Effect.Appear(info_strip, {queue:'end'});
      		status = SHOW_INFO;
      		break;
		} 

}

function toggle_menu(id) {

	var left_strip = $('left_strip'); // this is the menu div
	var info_strip = $("info_strip");
	var image_slide = $("image_slide_"+eval(current_picture));
	var nav_strip = $("nav_strip");
	var nav_box = $("nav_box");
	var elem = $(id); // interchanges SHOW/HIDE in the nav_box
	
	switch (status){ 
   		case SHOW_ALL : // if SHOW_ALL and menu button clicked hides left_srip and goes to state SHOW_INFO
   		    new Effect.Fade(left_strip, {queue:'end'});
   		    new Effect.Move(info_strip,{x:45, y: 0, mode: 'absolute'}, {queue:'end'});			   						
   		    new Effect.Move(image_slide,{x:270, y: 0, mode: 'absolute'}, {queue:'end'});			
			new Effect.Move(nav_box,{x:-1, y: 230, mode: 'absolute'}, {queue:'end'}); 			
			new Effect.Move(nav_strip,{x:4, y: 0, mode: 'absolute'}, {queue:'end'}); 						
			elem.innerHTML='SHOW<br/>MENU';
			status = SHOW_INFO;
      		break;
   		case SHOW_MENU : // if SHOW_MENU and menu button clicked hides left_srip and goes to state SHOW_IMAGE
   		    new Effect.Fade(left_strip, {queue:'end'});
   		    new Effect.Move(image_slide,{x:10, y: 0, mode: 'absolute'}, {queue:'end'});			
			new Effect.Move(nav_box,{x:-1, y: 230, mode: 'absolute'}, {queue:'end'}); 			
			new Effect.Move(nav_strip,{x:4, y: 0, mode: 'absolute'}, {queue:'end'}); 			
			elem.innerHTML='SHOW<br/>MENU';
			status = SHOW_IMAGE;
      		break;
      	case SHOW_INFO : // if SHOW_INFO and menu button clicked shows left_srip and goes to state SHOW_ALL
   		    new Effect.Move(image_slide,{x:447, y: 0, mode: 'absolute'}, {queue:'end'});			
   		    new Effect.Move(info_strip,{x:210, y: 0, mode: 'absolute'}, {queue:'end'});			   			
			new Effect.Move(nav_strip,{x:165, y: 0, mode: 'absolute'}, {queue:'end'}); 			
   			// This extra parameter is need to fix the Safari bug
   		    new Effect.Appear(left_strip, { duration: 2.0,from: 0.0001, to: 0.9999}, {queue:'end'});	      	
			elem.innerHTML='HIDE<br/>MENU';
      		status = SHOW_ALL;
      		break;
      	case SHOW_IMAGE : // if SHOW_IAMGE and menu button clicked shows left_srip and goes to state SHOW_MENU
   		    new Effect.Appear(left_strip);	      	
 			info_strip.style.left='207px';
   		    new Effect.Move(image_slide,{x:172, y: 0, mode: 'absolute'}, {queue:'end'}); 			
			new Effect.Move(nav_box,{x:-1, y: 230, mode: 'absolute'}, {queue:'end'}); 			
			new Effect.Move(nav_strip,{x:165, y: 0, mode: 'absolute'}, {queue:'end'}); 			
			elem.innerHTML='HIDE<br/>MENU';
      		status = SHOW_MENU;
      		break;
		}
}


//------------------------------------------
//  show_image
// 	Loads the picture to the background and applies the Appear effect
//
//	int img_num - the number of the picture we're going to load
//  str project - the project slug name
//------------------------------------------
function show_image(project,img_num) {

	var img_url = '../../../images/projects/'+project+'_'+img_num+'.jpg';

	//var image_slide = $("image_slide");
	var image_slide = $("image_slide_"+eval(img_num));
	//image_slide.style.display='none';
	switch (status){ 
   		case SHOW_ALL :
      		break;
   		case SHOW_MENU :  
      		image_slide.style.left='172px';
      		break;
      	case SHOW_INFO : 
      		image_slide.style.left='270px';
      		break;
      	case SHOW_IMAGE :  
      		image_slide.style.left='10px';
      		break;
		} 
	//image_slide.style.display='block';
	//image_slide.style.backgroundImage="url("+eval(project)[img_num].src+")";// displays the preloaded image
    //image_slide.style.backgroundImage="url("+img_url+")";
	n="image_slide_"+eval(img_num);

    setTimeout("new Effect.Appear(n);",200);
}

//------------------------------------------
// next_image
// 	Changes the current picture to the next picture
//
//  str project - the project slug name
//	total - total number of pictures
//------------------------------------------
function next_image(project,total) {
	var elem = $('link_'+current_picture);
	var image_slide = $("image_slide_"+current_picture);
	elem.className=""
	if (current_picture == total) {
		current_picture = 1;
	}
	else {
		current_picture = current_picture + 1; 
	}	
	var elem = $('link_'+current_picture);
	elem.className="selected"
	var img_url = '../../../images/projects/'+project+'_'+current_picture+'.jpg';
	//var image_slide = $("image_slide");

    new Effect.Fade(image_slide);
	p = project
	n=current_picture

	setTimeout("show_image(p,n)", 850);
}

//------------------------------------------
// prev_image
// 	Changes the current picture to the previous picture
//
//  str project - the project slug name
//	total - total number of pictures
//------------------------------------------
function prev_image(project,total) {
	var elem = $('link_'+current_picture);
	var image_slide = $("image_slide_"+current_picture);
	elem.className=""
	if (current_picture == 1) {
		current_picture = total;
	}
	else {
		current_picture = current_picture - 1; 
	}
	var elem = $('link_'+current_picture);
	elem.className="selected"
	var img_url = '../../../images/projects/'+project+'_'+current_picture+'.jpg';
	//var image_slide = $("image_slide");

    new Effect.Fade(image_slide);
	p = project
	n=current_picture

	setTimeout("show_image(p,n)", 850);
}


//------------------------------------------
// change_picture
// 	Changes the current picture to the picture given by the link
//
//	int item - the number of the picture we're going to change
//  str project - the project slug name
//------------------------------------------
function change_picture(item,project) { 

	var elem = $('link_'+current_picture);
	elem.className=""

	var image_slide = $("image_slide_"+current_picture);

	current_picture = item;
	var elem = $('link_'+current_picture);
	elem.className="selected"
	var img_url = '../../../images/projects/'+project+'_'+current_picture+'.jpg';


    new Effect.Fade(image_slide);

	p = project
	n=current_picture
    	
	setTimeout("show_image(p,n)", 850);

}



