var pageType = "NOT_DEFINED";

function menuRedraw() {

	$('.dropdown  ul').each(function() {

		var maxW = -1000;
		var minW = 1000;

		$(this).children().each(function() {
			if (maxW < $(this).text().length)
				maxW = $(this).text().length;
		});

		var FontSize = $('html').css('font-size');
		var FontSizeNum = parseFloat(FontSize, 10);

		if ($.browser.version == '6.0' || $.browser.version == '7.0') {
			$(this).children().css( {
				width : maxW * (FontSizeNum / 2.8) + (FontSizeNum / 2.8) * 10
			});
		}

	});

}

$(document).ready(function() {
	if ($("#bd .yui-ge.first .yui-u.first img").width() > 640)
		if ($.browser.version == '7.0') {
			$("#bd .yui-ge.first .yui-u.first img").css( {
				width : "620px"
			});
		} else
			$("#bd .yui-ge.first .yui-u.first img").css( {
				width : "640px"
			});

	$(".dropdown  ul ").each(function() {

		var maxW = -1000;
		var minW = 1000;

		// $(this).children().children().each(function() {
			//            
			// alert($(this).width());
			// if (maxW < $(this).width())
			// maxW = $(this).width();
			//                    
			// if (minW > $(this).width())
			// minW = $(this).width();
			// });

			$(this).children().each(function() {

				if (maxW < $(this).text().length)
					maxW = $(this).text().length;

				if (minW > $(this).text().length)
					minW = $(this).text().length;
			});
			// alert(maxW);

			if ($.browser.version == '6.0' || $.browser.version == '7.0') {

				$(this).children().css( {
					width : maxW * 5.5 + 50
				});
			}

			/*
			 * if (jQuery.trim($(this).text()).length > 20) {
			 * 
			 * var len = jQuery.trim($(this).text()).length * 7.5; if
			 * ($.browser.version == '7.0' || $.browser.version == '6.0') {
			 * $(this).parent().parent().children().css({ width: len }); } else
			 * $(this).parent().parent().css({ width: len }); }
			 */
		});

	var maxH = -99999;
	$(".row_handsets_content div").each(function() {
		if ($(this).height() > maxH)
			maxH = $(this).height();

	});

	// $(".row_handsets_content div").each(function() {
		if ($.browser.version != '7.0' && $.browser.version != '6.0') {
			$(".row_handsets_content div").css( {
				height : maxH,
				display : 'table-cell',
				verticalAlign : 'bottom'
			});

		} else {
			$(".row_handsets_content div ").css( {
				height : maxH
			});
		}

		// $(this h1).css({display:'inline-block'});

		// });

		if ($.browser.version == '7.0' || $.browser.version == '6.0') {
			$(".row_handsets_content").css( {
				width : '80px'
			});
			$('.row_handsets_content div').css( {
				width : 'auto',
				height : 'auto',
				marginLeft : '0px',
				marginRight : '0px',
				textAlign : 'center'
			});
			$('.row_handsets_content div h1').css( {
				marginLeft : '0px',
				textAlign : 'center'
			});
			// $(".reg_form_box select").css({ marginLeft: "10px" });
			$('.row_handsets_content div').each(function() {
				// alert($(this).height());
					var h = $('.row_handsets_content  h1').height();
					var count = $(this).children().size();
					var padding = maxH - count * h;

					$(this).css( {
						paddingTop : padding,
						border : '0px solid blue'
					});
				});

			$('.row_handsets_content').each(function() {
				var hi = ($(this).height());
				$(this).css( {
					height : hi
				});

				// alert($(this).css('height'));
				});

		}

		if ($.browser.version == '6.0') {
			// $('#doc').css({ width: '60em' });
			$('#menuDiv').css( {
				width : '70%'
			});
			$('#rightMenuDiv').css( {
				width : '25%'
			});
			// $('#menu').css({ width: '66%' });
			// $('').css({});
			$('.middlenav-container').css( {
				marginTop : '1%',
				marginLeft : '1%'
			});
			$('#middlenav div').css( {
				marginLeft : '7%'
			});

			$('.reg_form .img_help').css( {
				marginLeft : '0.5%'
			});

			$('.reg_form_box .img_help').css( {
				marginLeft : '3%'
			});

			$('.reg_form .yui-gf div.first').css( {
				width : '24%'
			});

			$('.dropdown li a').css( {
				borderRight : '0px solid #333333'
			});
			$('.dropdown li ul li a').css( {
				borderRight : '0px solid #333333'
			});

			$('.reg_form_box .yui-gf .yui-u span').css( {
				width : '36%',
				paddingLeft : '6%'
			});

			$('.reg_form .yui-gf .yui-u').css( {
				marginRight : '3%'
			});

			$('.reg_form .yui-gf .yui-u span').css( {
				width : '36%',
				paddingLeft : '6%'
			});

			$('.horizontalBox').css( {
				width : '29.4%'
			});
			$('.horizontalBox h4').css( {
				width : '100%'
			});

			$('.logo-panel-right').css( {
				width : 'auto',
				marginRight : '30px'
			});
			/* Regisrtarion Form */
			$('.reg_form form input:text').css( {
				width : '48%',
				background : '#FFFFFF'
			});
			$('.reg_form form input:password').css( {
				width : '48%',
				background : '#FFFFFF'
			});
			$('.reg_form form input:submit').addClass('reg_form_submit');
			/* Contact Form */
			$('.reg_form_box form input:text').css( {
				width : '150px',
				background : '#FFFFFF'
			});
			$('.reg_form_box form input:password').css( {
				width : '150px',
				background : '#FFFFFF'
			});
			$('.reg_form_box form select').css( {
				width : '152px',
				background : '#FFFFFF'
			});
			$('.reg_form_box form input:submit').addClass('reg_form_submit');
			$('.reg_form_box form input:reset').addClass('reg_form_box_reset');
			$('#hd .yui-gc .yui-u').css( {
				width : '30%',
				paddingRight : '0px'
			});
			$('#right_column').css( {
				marginRight : '2%'
			});
			// $(".dropdown li a").each(function() {
			// $(this).css({ borderRight: '1px solid #333' });
			// });

		}

		/** ***********18/03/2010*********** */

		var row_handset_div = $(".row_handsets").width();
		// alert(row_handset_div);
		/*
		 * $(".row_handsets").children().each(function() {
		 * alert($(this).width()); });
		 */
		var row_handset_count = $(".row_handsets").children().size();
		var row_handset_width = $(".row_handsets").children().width();

		// var row_handset_width = $(".row_handsets").children().css("width");

		// alert(row_handset_count + " " + row_handset_width);
		// if ($.browser.version == '6.0') { row_handset_div = 877; }
		row_handset_div = 915;
		var percent = (100 - (row_handset_width * row_handset_count)
				/ row_handset_div * 100)
				/ 2 + "%";
		// alert(percent);
		$(".row_handsets").css( {
			marginLeft : percent
		});
		// $(".row_handsets").children().css({ paddingLeft: "0%", border: "solid
		// 1px red" });

		/** ******************************** */
		/* prevent jump in ie8 when page is short */

		if ($.browser.version == '8.0') {
			$('body').css( {
				overflowY : 'scroll'
			});
		}

		/* menu adjustments */
		// $("ul.dropdown ul li ").css({ borderBottom: "1px solid #F7701E",
		// background:'#FFFFFF' });
		$("ul.dropdown li:last-child a").css( {
			borderRight : "0px solid red",
			borderBottom : "0px solid green",
			width : "auto"
		});

		$("ul.dropdown li ul li a").css( {
			borderBottom : "1px solid #F7701E",
			width : "auto"
		});
		$("ul.dropdown li ul li:last-child a").css( {
			borderBottom : "0px",
			width : "auto"
		});

		$(".items").mouseover(function() {
			$(".items").stop();
		});
		$(".items").mouseout(function() {
			$(".items").animate( {
				top : '-300px'
			}, 6000, 'linear', animate_in);
		});

		horizontalBox_elm = $('div.horizontalBox');
		menupanel_elm = ($('div.menu-panel'));
		boxschema1_elm = ($('div.box_schema1'));
		boxschema2_elm = ($('div.box_schema2'));
		boxschema3_elm = ($('div.box_schema3'));
		reg_form_elm = ($('div.reg_form'));
		reg_form_box_elm = ($('div.reg_form_box'));
		login_elm = ($('div.hd_href'));

	    if (pageType != "pricing") {

		$(function() {
			$("table").tablesorter({ 
		        // sort on the first column and third column, order asc 
		        sortList: [[0,0]] 
		    });
			$("tr:odd").addClass("odd");
			$("tr:even").addClass("even");
		});

		$('.head').click(function() {
			$("table").tablesorter( {

				widgets : [ "zebra" ],

				widgetZebra : {
					css : [ "odd", "even" ]
				}

			});

		});
	     }

		var current = -1;
		var elems = new Array();
		var elems_i = 0;
		$('.items').each(function() {
			elems[elems_i++] = $(this);
		});
		var num_elems = elems_i - 1;

		var animate_out = function() {
			elems[current].animate( {
				top : '-300px'
			}, 6000, 'linear', animate_in);
		}
		var animate_out_delay = function() {
			setTimeout(animate_out, 0);
			/**
			 * **************************** Change 1000 to make it
			 * longer/shorter/whatever
			 */
		}
		var animate_in = function() {
			current = current < num_elems ? current + 1 : 0;
			elems[current].css('top', '200px').animate( {
				top : '0px'
			}, 6000, 'linear', animate_out_delay);
		}
		try {
			animate_in();
		} catch (err) {
		}

		$(function() {

			$("ul.dropdown li").hover(function() {

				$(this).addClass("hover");
				$('ul:first', this).css('visibility', 'visible');

			}, function() {

				$(this).removeClass("hover");
				$('ul:first', this).css('visibility', 'hidden');

			});

			$("ul.dropdown li ul li:has(ul)").find("a:first").append(
					" &raquo; ");

		});

		/** **********************************MENU************************************************* */

		/*
		 * var timeout = 500; var closetimer = 0; var ddmenuitem = 0;
		 * 
		 * function jsddm_open() { jsddm_canceltimer(); jsddm_close();
		 * ddmenuitem = $(this).find('ul').css('visibility', 'visible'); }
		 * 
		 * function jsddm_close() { if (ddmenuitem) ddmenuitem.css('visibility',
		 * 'hidden'); }
		 * 
		 * function jsddm_timer() { closetimer = window.setTimeout(jsddm_close,
		 * timeout); }
		 * 
		 * function jsddm_canceltimer() { if (closetimer) {
		 * window.clearTimeout(closetimer); closetimer = null; } }
		 * 
		 * $(document).ready(function() { $('.dropdown > li').bind('mouseover',
		 * jsddm_open) $('.dropdown > li').bind('mouseout', jsddm_timer) });
		 * 
		 * document.onclick = jsddm_close;
		 */

		/** ******************************************************************************************* */

	});

function init() {
	var iBase = TextResizeDetector.addEventListener(onFontResize, null);

	// alert( "The base font size = " + iBase );
}
function onFontResize(e, args) {
	// alert(e.type);
	curvyCorners.redraw();
	menuRedraw();
}
/*
 * id of element to check for and insert test SPAN into
 */
TextResizeDetector.TARGET_ELEMENT_ID = 'hd';
/*
 * function to call once TextResizeDetector was initialized
 */
TextResizeDetector.USER_INIT_FUNC = init;

