var blnNoScript = false;
if (0 && $.browser.safari || ($.browser.msie && !(/msie [67]/.test(navigator.appVersion.toLowerCase())))) {
//if ($.browser.safari() || ($.browser.msie() && ($.browser.version.number() < 6))) {
	blnNoScript = true;
}
else {
   document.write('<style type="text/css" media="screen">');
   document.write(' @import "/_ui/udi07/css/udi07_.js.css";');
   document.write('</style>');
}

String.prototype.inArray=function(arr){
	if (typeof arr != 'object') {
		return false;
	}
	for ( var i in arr ) {
		if (typeof arr[i] != 'string') {}
		else if ( arr[i].toLowerCase() == this.toLowerCase() ) return true;
	}
	return false;
}

var document_content = [];
var document_ids = {};
var document_squares = [];
var document_dimensions = [];

document_current_pageMap = {'home':0, 'aboutus':1, 'services':2, 'technologies':3, 'contactus':4, 'ektron':5, 'phpcms':6, 'gorad':7};

function document_current(ix) {
	if (blnNoScript) return;
	if (!isNaN(ix)) {
		if (document_squares[document_squares.length-1]==ix) return;
		document_squares[document_squares.length] = ix;
	} else {
		if (typeof document_ids[ix] != 'undefined') {
			return document_current(document_ids[ix]);
		}
	}
	var ws = document_dimensions;
	var q;
	var i;
	var basis = 400;
	var ck = 1;

	// Load the content.
	// Scale
	for (q in ws) { //= 0; q<= contentBlocks; q++) {
		i = document_squares[document_squares.length-q-1];
		if (typeof i != 'undefined') {
			$('#eg'+q).css({ width:basis, height:basis }).html('<div class="padding">'+document_content[i]+'</div>');
//			$('#eg'+q).css({ width:basis, height:basis }).html('<div class="block">'+document_content[i]+'</div>');
		}
		else {
			$('#eg'+q).css({ width:basis, height:basis }).html('<div class="block"></div>');
		}

		if (q == 0) {
			if (document_squares.length == ck) {
//#				//$('#eg'+q).Scale(1,100,Math.round(ws[q][0]/basis*100)).css({ width: ws[q][0], height: ws[q][1] });
				$('#eg'+q).css({ width: ws[q][0], height: ws[q][1] });
			}
			else {
				$('#eg'+q).css({ width: ws[q][0], height: ws[q][1] });
			}
		} else {
		//	$('#eg'+q).Scale(1,100,Math.round(ws[q][0]/basis*100)).css({ width:  ws[q][0], height: ws[q][1] });
		//	$('#eg'+q).Scale(1,100,Math.round(ws[q][0]/basis*100)).queue(
		//		function(){
		//			this.css({ width:  ws[q][0], height: ws[q][1] });
		//		}
		//		);
		//	$('#eg'+q).css({ width:  ws[q][0], height: ws[q][1] });

			if (document_squares.length == ck) {
				$('#eg'+q).hover(
					function() {
						$(this).fadeTo("fast", 0.7)
					}, function() {
						$(this).fadeTo("fast", 1.0)
					}
				).click(
					function() {

						var hash = $('a:eq(0)', this).attr('name') || '';
                        var tmp = window.location.href.indexOf('#');

						var newLoc = (tmp == -1) ? window.location.href : window.location.href.substring(0, tmp);
                        window.location = newLoc+'#'+hash;

						var s = 1*this.id.substring(2, 100);
						if(s <= document_squares.length-1) {
							s = document_squares[document_squares.length-s-1];
							document_current(s);
						}
					}
				// );
//#				//).Scale(1,100,Math.round(ws[q][0]/basis*100)).animate({ width:  ws[q][0], height: ws[q][1] }, 250);
				).animate({ width:  ws[q][0], height: ws[q][1] }, 250);

			}
		}
	}

	// Re-fix the size.
	for (q in ws) {
		$('#eg'+q).css({
		  width:  ws[q][0],
		  height: ws[q][1],
		  left:   ws[q][2],
		  top:    ws[q][3]
		});
	}

	// Update the printable content.
	var sq = ['0'];
	$('#printableContent').html('');
//	$('#printableContent').html(document_squares[0]).wrap('<div></div>');
	for (q in ws) {
		i = document_squares[document_squares.length-q-1];
		if (typeof i == 'undefined') {
			continue;
		}
		if (typeof document_content[i] == 'undefined') {
			continue;
		}

		if (!(""+i).inArray(sq)) {
			$('#printableContent').append('<div class="content">' + document_content[i] + '</div>');
			sq[sq.length] = '' + i;
		}
	}
//	alert($('#printableContent').html());
}


$('document').ready(
	function() {
	  // Navigation
	  $('#nav li').hover(function() {
	      $(this).addClass('hover');
	  },function() {
	      $(this).removeClass('hover');
	  }).click(function() {
	      $(this).find('a').click();
	  });
	    
	  if (blnNoScript) return;

	  $('body').addClass('js');
      $('html').css({backgroundColor: '#f90'});
      $('body .content').css('display', 'none');


	  var i;
	  var q;

	  $('#browserWarning').remove();

	  // Read in the content blocks.
	  q = $('#printableContent').children('div');
	  for (i = 0; i < q.length; i++) {
		document_ids[q.eq(i).attr('id')] = i;
		document_content[i] = q.eq(i).html();
	  }

	  // Create the blocks.
	  $('#navContainer').after('<div id="blockContainer" class="noPrint"></div>');
	  for (i = 0; i < 20; i++) {
		  $('#blockContainer').after('<div id="eg' + i + '" class="block"></div>');
	  }

	  var w1 = 300;
	  var contentBlocks = 20;
	  var x = Math.round(Math.min((self.innerHeight || jQuery.boxModel && document.documentElement.clientHeight || document.body.clientHeight), .618*(self.innerWidth || jQuery.boxModel && document.documentElement.clientWidth || document.body.clientWidth))) - 30;
	  w1 = x;
	  var w2 = Math.floor(w1 * .61803399); // w1 * .618
	  var w = w1+w2;
	  var el;
	  var b = Math.round(((self.innerHeight || jQuery.boxModel && document.documentElement.clientHeight || document.body.clientHeight) + w1)/2);
	  var r = Math.round(((self.innerWidth || jQuery.boxModel && document.documentElement.clientWidth || document.body.clientWidth) + w)/2);
	  var borderw = 1;
	  var ws = document_dimensions;
	  var wb = ((w1+w2) + 3);

	  var t = (b - w1 - borderw);
	  var l = (r - w2 - w1 - 2 * borderw);
	  var test = 0;

	  // Move the nav bar
		$('#navContainer').css({
			width:  w1,
		//	height: 20,
			top:    t+borderw,
			left:   r-w1
		});

	  // Position background
	  $("#blockContainer").css({
		width: wb,
		height: w1 + (borderw * 2),
		top: t,
		left: l
	  });

	  // Resize and move boxes
	  for(i=0; i<=contentBlocks; i++) {
		el='#eg'+i;
		w=w1;
		if(test == 1) {
		  $(el).hide();
		  continue;
		}

		test = Math.abs((b-t) / (r-l));
		if (test > 1) {
			test = 1 / test
		}
		test = Math.abs(test - .618);
		if (test > .138) {
			ws[i] = [r-l-borderw, b-t-borderw, l+borderw, t+borderw];
			test = 1;
		}
		else {
			ws[i] = [w, w, r-w, b-w];
		}

		$(el).css({
		  width:  ws[i][0],
		  height: ws[i][1],
		  left:   ws[i][2],
		  top:    ws[i][3]
		});

		if(i%2 == 0) {
		  r-=w+borderw;
		}
		else {
		  b-=w+borderw;
		}
		w1=w2;
		w2=Math.min(w1,w-w1-borderw);
	  }


	  document_current(0);

	  $('body .content').css('display', '');

	  var bodyFont;
	  //if ($.browser.msie) {
	  //    bodyFont = (Math.round( $('#eg0').width() * 1.75 ) /100);
	  //} else {
	      bodyFont = (Math.round( $('#eg0').width() * 2.25 ) /100);
	  //}

	      // set body font sized based off of rendered size of eg0
      $('body').css({'fontSize': bodyFont+'px' });
      $('body.js #nav li a').css( {'width':'24%'} );

	      // load current pane if #hash is set
      if (window.location.hash && window.location.hash != '#' &&  (typeof document_current_pageMap[ window.location.hash.substring(1) ] != undefined)  ) {
          document_current(document_current_pageMap[ window.location.hash.substring(1) ]);
      } else {
          setTimeout("document_current(1)", 1250);
      }

	}
);
