var millesg = 5000;

function preload(images) {
    if (document.images) {
        var i = 0;
        var imageArray = new Array();
        imageArray = images.split(',');
        var imageObj = new Image();
        for(i=0; i<=imageArray.length-1; i++) {
            //document.write('<img src="' + imageArray[i] + '" />');// Write to page (uncomment to check images)
            imageObj.src=images[i];
        }
    }
	
}
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };
var entrap =0;
function MyPreload(obj){
		jQuery('#top_gallery').css("background-image", "url(images/preloader.gif)");
		jQuery('#top_gallery').css("backgroundPosition","center");
		//jQuery('#top_galery_title').css('background','none');
                    jQuery(obj).preload({
                        URL: 'base',
                        onFinish: function(e){
			href  = href.replace("http://arconeng.ca/", "");
			href  = href.replace("http://www.arconeng.ca/", "");
if(navigator.appName == 'Netscape'){


			jQuery('#top_gallery').css("backgroundPosition","center");
		
			if('tmp/938x371x0x_CUT_x_AA00923-01.jpg' == href){
	
			jQuery('#top_gallery').css("backgroundPosition","26% 50%");
		
			}

			if('tmp/938x371x0x_CUT_x_069809_rev.jpg' == href){
			jQuery('#top_gallery').css("backgroundPosition","33% 50%");
			}
			
			if('tmp/938x371x0x_CUT_x_FIRE_frontpage_rev.jpg' == href){
			
			jQuery('#top_gallery').css("backgroundPosition","27% 50%");
			
			
			}

			if(href == 'tmp/938x371x0x_CUT_x_AA61105_3D_rev.jpg'){
			jQuery('#top_gallery').css("backgroundPosition","4% 50%");
			}

			if('tmp/938x371x0x_CUT_x_AA30911_35X_SEM_rev.jpg' == href){
				jQuery('#top_gallery').css("backgroundPosition","40% 50%");

			}

			if('tmp/938x371x0x_CUT_x_AA61201_rev2.jpg' == href){
				jQuery('#top_gallery').css("backgroundPosition","41% 50%");

			}

			if('tmp/938x371x0x_CUT_x_RMI_IMG_5098.jpg' == href){
				jQuery('#top_gallery').css("backgroundPosition","27.5% 50%");

			}
}else{

jQuery('#top_gallery').css("backgroundPosition","center");
			
			if('tmp/938x371x0x_CUT_x_AA00923-01.jpg' == href){
			jQuery('#top_gallery').css("backgroundPosition","26% 50%");	
			}

			if('tmp/938x371x0x_CUT_x_069809_rev.jpg' == href){
			jQuery('#top_gallery').css("backgroundPosition","33% 50%");
			}
			
			if('tmp/938x371x0x_CUT_x_FIRE_frontpage_rev.jpg' == href){
			jQuery('#top_gallery').css("backgroundPosition","28% 50%");
			}

			if(href == 'tmp/938x371x0x_CUT_x_AA61105_3D_rev.jpg'){
			jQuery('#top_gallery').css("backgroundPosition","4% 50%");
			}

			if('tmp/938x371x0x_CUT_x_AA30911_35X_SEM_rev.jpg' == href){
				jQuery('#top_gallery').css("backgroundPosition","39.5% 50%");

			}

			if('tmp/938x371x0x_CUT_x_AA61201_rev2.jpg' == href){
				jQuery('#top_gallery').css("backgroundPosition","41% 50%");

			}

			if('tmp/938x371x0x_CUT_x_RMI_IMG_5098.jpg' == href){
				jQuery('#top_gallery').css("backgroundPosition","28% 50%");

			}



}

//alert(href)
				jQuery('#top_gallery').css("background-image", "url(" + href + ")");
                        }
                        });
}

function muestraMensaje(){
	$vattid = jQuery('.get_trans .active').attr('id');
		
		if($vattid  != "last"){
		jQuery('.get_trans .active').next().addClass("active");
		jQuery('.get_trans .active:first').removeClass("active");
		
		jQuery('#top_galery_title  ul  .activea a').removeClass("select");
		jQuery('#top_galery_title  ul  li.activea').next().addClass("activea");
		
		jQuery('#top_galery_title  ul  li.activea:first').removeClass("activea");
		jQuery('#top_galery_title  ul  .activea a').addClass("select");
		
		}else{
			jQuery('.get_trans .active').removeClass("active");
			jQuery('.get_trans li:first').addClass("active");
		
			jQuery('#top_galery_title  ul  .activea a').removeClass("select");
			jQuery('#top_galery_title  ul  .activea').removeClass("activea");	
			jQuery('#top_galery_title  ul  li:first').addClass("activea");	
		
	
		jQuery('#top_galery_title  ul  .activea a').addClass("select");
		
		}
		this_href = jQuery('.get_trans .active a');
		
		//alert(jQuery(this_href).attr('title'));
		
		jQuery('#top_galery_title span').html(jQuery(this_href).attr("title"));
		
		jQuery('#top_galery_title  ul  .activea a').addClass("activea");
		
		href =jQuery('#top_galery_title  ul .activea a').attr("href");
		
		MyPreload(jQuery('#top_galery_title  ul li .select'));
		//alert(jQuery(this_href).attr('href'));
	  /*  jQuery('#ajax').fadeOut(500,function(){
		    jQuery('#ajax').load(jQuery(this_href).attr('href') + ' #content',function(data){
			jQuery('#ajax').prepend('<h1>' + jQuery(this_href).text() + '</h1>').fadeIn(500);
			
		    });
		});*/
		slideshow = setTimeout(muestraMensaje, millesg);
}


$(document).ready(function(){


var slideshow = setTimeout(muestraMensaje, millesg);

jQuery('.get_trans li:first').addClass("active");
jQuery('.get_trans li:first').attr("id","first");
jQuery('.get_trans .last').attr("id","last");
jQuery('#top_galery_title  ul li:first').addClass("activea");


	jQuery('.get_trans a').click(function(){
	    jQuery('#top_galery_title a').eq(jQuery(this).index('.get_trans a')).click();
	   // alert("aaaaa");
	   	
		this_href = jQuery(this);
		this_href.addClass("active");
		//alert(jQuery(this_href).attr('href'));
	    jQuery('#ajax').fadeOut(500,function(){
		    jQuery('#ajax').load(jQuery(this_href).attr('href') + ' #content',function(data){
			jQuery('#ajax').prepend('<h1>' + jQuery(this_href).text() + '</h1>').fadeIn(500);
		    });
		});
	
	
		
	//    jQuery.ajax({
	//	url: this_href,
	//	async: false,
	//	context: '#content',
	//	success: function(data){
	//	    jQuery('#ajax').replaceWith(data);
	//	}
	//	});

	
	
	/****************** ***************************/
			    jQuery('#ajax').fadeOut(500,function(){  
													 clearTimeout(slideshow);
			$("#top_gallery").load("subimages.php?href="+jQuery(this_href).attr('href')); 
});
	
	/****************** ***************************/
	
	
	
	    return false;
	    });
    
	
	jQuery("form#right_panel input, form#right_panel textarea").focus(function(){
	    if (jQuery(this).attr('value')=='Your message' || jQuery(this).attr('value')=='Name*' || jQuery(this).attr('value')=='Phone*' || jQuery(this).attr('value')=='E-mail*'){
		jQuery(this).attr('old_value',jQuery(this).attr('value')).attr('value','');
		};
	    });
	jQuery("form#right_panel input, form#right_panel textarea").focusout(function(){
	    if (jQuery(this).attr('value').length==0){
	    jQuery(this).attr('value',jQuery(this).attr('old_value'));
	    }
	    });
	

	
	
	$("#top_galery_title a").each(function(){
		
		});

    	$('#menu li:not(.active) a')
		.css( {backgroundPosition: "0 -35px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 0px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 -35px)"}, {duration:300, complete:function(){
				$(this).css({backgroundPosition: "0 -35px"})
			}})
		})
		
    	$('a.button')
		.css( {backgroundPosition: "0 -35px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 0px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 -35px)"}, {duration:300, complete:function(){
				$(this).css({backgroundPosition: "0 -35px"})
			}})
		})
		
		
		
	$("#top_galery_title a:not(.select)").click(function(){
														
		$("#top_galery_title a").removeClass("select");
		$(this).addClass("select");
		$("#top_galery_title span").text($(this).attr("title"));
		href = $(this).attr("href");
		
		MyPreload(jQuery(this));
		//$("#top_gallery").css("background-image", "url(" + href + ")");
		return false;
		});
	
	
		$("#top_galery_title a:first").click();
    });
