var _gallery = null;
var _galleryEl = null;
var _duration = 0;
var _numElement = null;
var _numElementLink = null;
var _numElActive = false;
var _n = false;
var _timer = false;

function initPage() {
	_gallery = $("#slideshow");
	_galleryEl = $("ul.image li", _gallery);
	_galEl = "li";
	_duration = 400;
	_timeSwitching = 5000;
	_numElementLink = $("ul li", _gallery);
	_numElement = $("ul li", _gallery);
	
	$(_galleryEl).not(".active").fadeOut(10);
		
	_timer = setTimeout('nextEl()',_timeSwitching);
	SetUpFieldHides();
}
function fadeElement(){
	$(_galleryEl).filter(".active").fadeOut(_duration).removeClass("active");
	$(_galleryEl).filter(".next").fadeIn(_duration).addClass("active").removeClass("next");
}

function nextEl(){
	if ($(_galleryEl).filter(".active").next().is(_galEl)) {
		$(_galleryEl).filter(".active").next().addClass("next");
	} else {
		$(_galleryEl).eq(0).addClass("next");
	}
	fadeElement();
	_timer = setTimeout('nextEl()',_timeSwitching);
}

function SetUpFieldHides()
{


 $('.clearbox').addClass("idleField");  
     $('input[type="text"]').focus(function() {  
         $(this).removeClass("idleField").addClass("focusField");  
         if (this.value == this.defaultValue){  
             this.value = '';  
         }  
         if(this.value != this.defaultValue){  
             this.select();  
         }  
     });  
     $('.clearbox').blur(function() {  
         $(this).removeClass("focusField").addClass("idleField");  
         if ($.trim(this.value) == ''){  
             this.value = (this.defaultValue ? this.defaultValue : '');  
         }  
     });  
//    $('.clearbox').each(function(){
//        var temp = $(this).val();
//        $(this).focus(function(){
//            $(this).val('');
//        });
//        $(this).blur(function(){
//            if($(this).val()!=''){
//                $(this).val(temp);
//            }
//        });
//    });
}

if (window.addEventListener)
	window.addEventListener("load", initPage, false);
else if (window.attachEvent)
	window.attachEvent("onload", initPage);
