function runningInGr8stuff() { 
  try {
	if ( typeof(parent.inGr8stuff)=='function') { return true; } else { return false; }
  } catch(e) { return false; }
//if (parent.location.href==location.href) { return false; } else { return true; } 
}

try {

$(function() {
// ***** TEST **
//var p=definePalette(8,'#FF0000','#AA001F'); 
//var p=definePalette(8,'#FF0000','#F0FFFF'); 
//alert(p);
// *************
	var loc=window.location.href.toLowerCase().replace(/\\/g,'\/');
	
	$('.buttons').each( function() {
		var cp='; CURSOR: pointer', onc='', a=$(this).find('a'), hr=a.attr('href'),
			tg=a.attr('target'), t=a.attr('title'), txt=a.html(), fc=a.css('color');
		if (hr===undefined) { hr=''; cp=''; } else {
			if (hr.toLowerCase().indexOf('javascript:')>=0) {
				onc=' onclick="'+$.trim(hr.replace(/javascript\:/i,''))+'"';
			} else {
				if (tg===undefined || tg=='') { 
					onc=' onclick="window.location.href='+"'"+hr+"';"+'"';
				} else {
					onc=' onclick="window.open('+"'"+hr+"');"+'"'; 
					a.attr('target','');
				}
			}
			if (t!==undefined) onc+=' title="'+t+'"';
//alert(onc);
		}
		var w=$(this).width()+20, h=$(this).height(),
		d='<DIV style="PADDING: 5px; WIDTH: '+w+'px; HEIGHT: '+h+'px'+cp+'" class="'+$(this).attr('class')+' roundbut" align="center"'+onc+'>',
		h=$(this).parent().html();
		if (txt!==undefined) {
			if (fc!==undefined) txt='<font color="'+fc+'">'+txt+'</font>';
			h=h.replace(/\<a[\s\S]+\/a>/i,txt);
		}
//alert(d+h+'</div>');
		$(this).parent().html(d+h+'</div>');
	});

	if (loc.indexOf('webmail')>=0) return;
	if (loc.indexOf('catalogue')>=0) return;

//	$('.roundbut').corners('5px 5px transparent');
//	$('.header_buttons, .content_div, .header_app_rounded').corners('5px 5px transparent');

	$('.roundbut').gr8round({size:8});
	$('.header_buttons, .header_app_rounded').gr8round({size:8});
	$('.content_div').gr8round({size:12});
	$('.title_round').gr8round({size:{width:12,height:12},corners:'topleft topright bottomleft bottomright'});
	$('.round_blue').gr8round({size:8});
	$('.round_white').gr8round({size:8});
	$('.roundimg').gr8round({size:12,image:true});
/*
// Resize not needed on this site, if required then uncomment
	$(window).resize( function() { 
		$('.roundimg').gr8round({action:'resize'});
		$('.roundimg').gr8round({size:12,image:true});
	});
*/

	$('.header a,.round_blue a,.footer a').mouseenter(function () { 
		var e=this, gr=$(this).find('.gr8rounded');
		if ($(gr).size()>0) e=gr;
		var img=$(e).find('img');
		if ($(img).size()>0) var e=img;
		$(e).fadeTo('fast', 0.2, function() {
			// Animation complete.
			$.sound.play('whoosh.mp3');
			$(e).fadeTo(800,1);
		});
	});
//	$('a').mousedown(function () { $.sound.play('crisp.mp3'); });
	
//	$('body').load( function() { 

		// Set the header title if this is not the index page

		if (loc.indexOf('index.htm')<0) {
			var title='';
			$('.menuitem').each( function (){
				if ($(this).find('a').size()<1) {
					title=$(this).text(); return;
				}
			});
			if (title=='') {
				var y=loc.lastIndexOf('\/')
				if (y>=0) { var pg=loc.substr(y+1); } else { var pg=loc; }
				pg=pg.replace(/\.htm/,'');
				switch (pg) {
					case 'products_display': { title='Services'; 
												$('.header_row1_col2_bg').css('background','url(pics/pic_top_gray.jpg) top left no-repeat');
												break; }
					case 'type_0': { title='Our Services'; break; }
					case 'gallery': { title='Photo Gallery'; break; }
					case 'application': { title='Application - Internet Access'; break; }
					case 'application_internet_phone': { title='Application - Internet Phone'; break; }
					case 'e0001': { title='Wireless Internet'; break; }
					case 'e0002': { title='Telephone Services'; break; }
					case 'e0004': { title='ISP Services'; break; }
					case 'e0005': { title='Wireless Networks'; break; }
					case 'e0006': { title='Services to Schools'; break; }
					case 'e0007': { title='Other Services'; break; }
				}
				if (pg.substr(0,2)=='e0') { $('.header_row1_col2_bg').css('background','url(pics/pic_top.jpg) top left no-repeat'); }
			}
			if (title=='Home') title='';
			//title='Contact Us';
			if (title!='') {

				var e=$('#hdr_title'), otit=e.text();
				otit=otit.substr(otit.indexOf('. ')+2);
				$(e).fadeTo('slow', 0, function() {
					$(this).html(title+'<br>'+otit);
					$(this).fadeTo(800, 1);
				});
//			$('#hdr_title').html(title).css('font-size','48px').css('padding-top','24px');
			}
		}
//	});
	
	$.sound.load('whoosh.mp3');
//	$.sound.load('sparkles.mp3');
//	$.sound.load('crisp.mp3');
	
	$('.header_buttons a').gr8titletips({position:'left'});
	$('.header_app_rounded a').gr8titletips({position:'bottomleft'});
	$('.header_contact a').gr8titletips({position:'bottomright'});
	$('.menuitem a').gr8titletips({position:'bottomcenter'});
	$('.footer a').gr8titletips({position:'topcenter'});
	$('.round_blue a').gr8titletips({position:'bottomcenter'});

	$('iframe').load(function() { 
		try {
		$(this).height($(this).contents().height());
		} catch (e) {}
	});

});

} catch(e) {}

function goto_folder(folder) {
	if (runningInGr8stuff()) {
		parent.we_submenu('^gotofolder_'+folder+'/index.htm');
	} else { location.href=folder+'/index.htm'; }
}

function goto_root() {
	if (runningInGr8stuff()) {
		parent.we_submenu('^gotofolder_../');
	} else { location.href='../index.htm'; }
}

function backFromFolder(pg) {
	if (runningInGr8stuff()) {
		parent.we_submenu('^gotofolder_../'+pg);
	} else { location.href='../'+pg; }
}

// ***** TEST ********
function definePalette(colors,col1,col2) {
	var phase=[], red=[], green=[], blue=[], palette=[];

	// Define perc of color to increase
	phase[0]=0;
	for (var i=1; i<colors-1; i++) {
		phase[i]=(i*((256/colors/256)));
	}
	phase[colors]=1;

	red[0]=parseInt(col1.substr(1,2),16);
	green[0]=parseInt(col1.substr(3,2),16);
	blue[0]=parseInt(col1.substr(5,2),16);

	red[colors-1]=parseInt(col2.substr(1,2),16);
	green[colors-1]=parseInt(col2.substr(3,2),16);
	blue[colors-1]=parseInt(col2.substr(5,2),16);

	for (var i=1; i<colors-1; i++) {
		red[i]=red[0]+Math.ceil((red[colors-1]-red[0])*phase[i]);
		green[i]=green[0]+Math.ceil((green[colors-1]-green[0])*phase[i]);
		blue[i]=blue[0]+Math.ceil((blue[colors-1]-blue[0])*phase[i]);
		palette[i]=toHexStr(red[i])+' '+toHexStr(green[i])+' '+toHexStr(blue[i]);
	}
	palette[0]=toHexStr(red[0])+' '+toHexStr(green[0])+' '+toHexStr(blue[0]);
	palette[colors-1]=toHexStr(red[colors-1])+' '+toHexStr(green[colors-1])+' '+toHexStr(blue[colors-1]);

	return palette.join(' ');
}

function toHexStr(d) {
	var s='00'+d.toString(16);
	return s.substr(s.length-2);
}



