/** add_page_load_event.js allows us to run one or multiple functions on page load
The advantage of this funtion is it won't override any previously set onload functions,
and also that it will trigger at the point of HTML being ready, rather than waiting for every image to load */

/** Code to run on page load, including image rollovers and anything else fancy */
function page_setup()
{
	// initialise plugins
	$("#sf-menu").eq(0).supersubs({ 
		minWidth:    10,   // minimum width of sub-menus in em units 
		maxWidth:    27,   // maximum width of sub-menus in em units 
		extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
						   // due to slight rounding differences and font-family 
	}).superfish();
	
	//make any area on the page with a .contentblock class animate into view
	//contentblocks_show();

	// if the page is using the s3slider then start it
   	if ($('#s3slider').length)
	{
		$('#s3slider').s3Slider({
     	 		timeOut: 10000
   		});
	}
	
	textfield_setDefaultValue( 'searchField', 'Search...' );
  	
   	// if the page is using the banner then prepare it
   	banner_setup();
}

$(document).ready( page_setup );

function contentblocks_show()
{
    var i = -1;
    var arr = $("div.contentblock");
    (function() 
    {
   		/** animate the content block */
    	if(arr[++i]) $(arr[i]).fadeIn(600, arguments.callee)
    })();
}

// prepare the rotating banner for feature news items 
function banner_setup()
{		
	var transitionTimeout = 20000;
	var transitionSpeed   = 1000;
	var transitionStagger = 5000;
	
	if( $('.gallery .gallery-inner ul').eq(0).length < 1 ) return false;
	
	$('.gallery .gallery-inner').eq(0).append( '<div class="cycleNav"></div>' );
	
	$('.gallery .gallery-inner ul').eq(0)
	.cycle({ 
		fx:     'fade', 
		speed:  transitionSpeed, 
		timeout: transitionTimeout,
		pager:  '.cycleNav' ,
		//next:   '.cycleNext', 
		//prev:   '.cyclePrev',
		pause: 1
	});
}

function show_emag(title, dir)
{
 popupWindow('filelib/emags/'+dir+'/emag.html', 'emag', 650, 900);
} 

function popupWindow(URLtoOpen,windowName,height,width,resize,address)
{
  resize = resize?"yes":"no";
  address = address?"yes":"no";
  windowFeatures = "menubar=no,scrollbars=no,location=no,favorites=no,resizable=no,status=no,toolbar=no,directories=no,status=no,address="+address;
  winLeft = (screen.width-width)/2;
  winTop = (screen.height-(height+110))/2;
  return window.open(URLtoOpen,windowName,"width=" + width +",height=" + height + ",left=" + winLeft + ",top=" + winTop + "," + windowFeatures);
}
