var firstFocus = true;

function clearText(frm)
{
	
	if(firstFocus)
	{
		document.getElementById(frm).value = '';
		document.getElementById(frm).style.textAlign = 'left';
		firstFocus = false;
	}
	
}

function checkSearchFrm(frm)
{	
	regEx = /^[\s]*$/g;
	if(!regEx.test(frm.searchTxt.value) && frm.searchTxt.value.length >= 4)
	{	
		return true;
	}   
	else
	{
		alert('The search text must have at least 4 characters.');
		frm.searchTxt.focus();
		return false;
	}
}

var transition = false;
    function slideSwitch(direction) {
    if (transition) return;
    transition = true;
        var $active = $('#slideshow DIV.active');
        var $activespan = $('#counter SPAN.activespan');

        if ($active.length == 0) $active = $('#slideshow DIV:last');
        if ($activespan.length == 0) $activespan = $('#counter SPAN:last');

        if (direction == 'right') {
            var $next = $active.next().length ? $active.next() : $('#slideshow DIV:first');
            var $nextspan = $activespan.next().length ? $activespan.next() : $('#counter SPAN:first');
        }
        else {
            var $next = $active.prev().length ? $active.prev() : $('#slideshow DIV:last');
            var $nextspan = $activespan.prev().length ? $activespan.prev() : $('#counter SPAN:last');
        }
    $active.addClass('last-active');
    $activespan.removeClass('activespan');
    $nextspan.addClass('activespan');

    $next.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function() {
            $active.removeClass('active last-active');
            transition=false;
        });
    }

    var playSlideshow = setInterval("slideSwitch('right')", 4000);

function scrLeft() {
    clearInterval(playSlideshow);
    slideSwitch('left');
    playSlideshow = setInterval("slideSwitch('left')", 4000);
};

function scrRight() {
    clearInterval(playSlideshow);
    slideSwitch('right');
    playSlideshow = setInterval("slideSwitch('right')", 4000);
};

function clickMe(a) {
    clearInterval(playSlideshow);
    var $active = $('#slideshow DIV.active');
    var $activespan = $('#counter SPAN.activespan');
    var $next = $('#slideshow DIV#pic' + a);
    var $nextspan = $('#counter SPAN#p' + a);

    if ($active.length == 0) $active = $('#slideshow DIV:last');
    if ($activespan.length == 0) $activespan = $('#counter SPAN:last');
    if ($next.length == 0) $next = $('#slideshow DIV:first');
    if ($nextspan.length == 0) $nextspan = $('#counter SPAN:first');

    $active.addClass('last-active');
    $activespan.removeClass('activespan');
    $nextspan.addClass('activespan');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
        playSlideshow = setInterval("slideSwitch('right')", 4000);
}

var captions;

function showCaption(a) {
    document.body.style.cursor = 'pointer';
    document.getElementById('caption').innerHTML = captions[a];
}
function hideCaption(a) {
    document.body.style.cursor = '';
    document.getElementById('caption').innerHTML = '';
}
function stopSlide(){
    clearInterval(playSlideshow);
}
function startSlide(){
    clearInterval(playSlideshow);
    playSlideshow = setInterval("startLongSlide()", 4000);
}
function startLongSlide() {
    clearInterval(playSlideshow);
    slideSwitch('right');
    playSlideshow = setInterval("slideSwitch('right')", 4000);
}