/*
 Javascript functions by Kamran
*/

// Check which object we can work with
(document.layers) ? layerobject=true : layerobject=false;
(document.all) ? allobject = true: allobject = false;
(document.getElementById) ? dom = true : dom = false;


function collapse(id) {
alert(id);
jQuery(id).slideUp(250, 'easeOutQuad');
}

function expand(id) {
jQuery(id).slideDown(250, 'easeOutQuad');
}


/**
* Function to change visibility
*
*/
function changeVisibility(id,action)
{
	switch (action)
	{
	case "show":
		if (layerobject)
			document.layers[''+id+''].visibility = "show";
		else if (allobject)
			document.all[''+id+''].style.visibility = "visible";
		else if (dom)
			document.getElementById(''+id+'').style.visibility = "visible";
	break;
	case "hide":
		if (layerobject)
			document.layers[''+id+''].visibility = "hide";
		else if (allobject)
			document.all[''+id+''].style.visibility = "hidden";
		else if (dom)
			document.getElementById(''+id+'').style.visibility = "hidden";
	break;
	default:
		return;
	}
return;
}
/**
* Function to change size
*
*/
function changeSize(id,x,y)
{
	if (layerobject)
	{
		document.layers[''+id+''].width = x;
		document.layers[''+id+''].height = y;
	}
	else if (allobject)
	{
		document.all[''+id+''].style.width=x;
		document.all[''+id+''].style.height=y;
	}
	else if (dom)
	{
		document.getElementById(''+id+'').style.width=x+"px";
		document.getElementById(''+id+'').style.height=y+"px";
	}
return;
}

/**
* Function to move items
*
*/

function changePosition(id,x,y)
{
	if (layerobject)
	{
		document.layers[''+id+''].left = x;
		document.layers[''+id+''].top = y;
	}
	else if (allobject)
	{
		document.all[''+id+''].style.left=x;
		document.all[''+id+''].style.top=y;
	}
	else if (dom)
	{
		document.getElementById(''+id+'').style.left=x+"px";
		document.getElementById(''+id+'').style.top=y+"px";
	}
return;
}

/**
* Function to set text
*
*/
function setInnerText(id,text)
{
	if (layerobject)
		document.layers[''+id+''].innerText = text;
	else if (allobject)
		document.all[''+id+''].innerText=text;
	else if (dom)
	{
		var old = document.getElementById(''+id+'').firstChild;
		var txt = document.createTextNode(text);
		document.getElementById(''+id+'').replaceChild(txt, old);
	}
return;
}
function slideSwitch() {
    var $active = jQuery('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = jQuery('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : jQuery('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

jQuery(function() {
    setInterval( "slideSwitch()", 5000 );
});