$(document).ready(function(){
	$("#pageTitle").remove().clone().prependTo("#grid_wrapper");
	//$("#siteSearch input[name='qt']").val("Search");	
		
	// to hide empty flyouts
	$(".flyoutMenu").each(function() { 
       if(!$(this).is(":has(div)")) { $(this).addClass('hideFlyout');}
	 });
	
	// to make flyout transparent
	$(".flyoutMenu").css({'opacity': '0.95'}); 		
	
	/* Start - Add width and height attribute for the flash banner in the right column */
	$("#gridRight .rightModuleAds object").attr("width","241");
	$("#gridRight .rightModuleAds object").attr("height","88");
	$("#gridRight .rightModuleAds embed").attr("width","244");
	$("#gridRight .rightModuleAds embed").attr("height","89");
	/* End - Add width and height attribute for the flash banner in the right column */

	/* Remove title links which don't have product pages */
	var pageURL = document.location.href;
	var url = pageURL.substring(pageURL.lastIndexOf('/'), pageURL.length);
	$('.moduleCat .moduleCont .moduleTitle a').each(function(i) {
	   if($(this).attr("href") == url)
	   {
			$(this).removeAttr("href");
			$(this).css("color","#666666");
	   }
	   else
		{
			$(this).before('<img src="/chartisint/internet/common/files/aiunew_anchor_tcm801-200447.gif"/>');
		}
	});

	//Enable Country wise cookie					   
	if(!$("#mastHead .topLinks .onPage")[0]){	
		if(readCookie("GEOLOCATION_COOKIE")) 
		{
			var getCountry = getCountryName(readCookie("GEOLOCATION_COOKIE"));
			var $couNTryBlk = '<div class=onPage><div class=countryClass>'+getCountry+' </div></div>';
			$("#mastHead .topLinks").prepend($couNTryBlk);
		}
		else
		{
			try{if(flashCountry){flashCountry = flashCountry.replace("%26", "&");writeCookie("country",flashCountry);}}
			catch(e){}
			var $couNTryBlk = '<div class=onPage><div class=countryClass>'+readCookie("country")+' </div></div>';
			$("#mastHead .topLinks").prepend($couNTryBlk);
		}
	}  	
	else
	{
		var countryLabel = $("#mastHead .topLinks .onPage").html();
		$("#mastHead .topLinks .onPage").remove();
		var $couNTryBlk = '<div class=onPage><div class=countryClass>'+countryLabel+' </div></div>';
		$("#mastHead .topLinks").prepend($couNTryBlk);
	}


	// to change search field value for Romania site
	var currURL =  window.location+''; 
    var pageName = currURL.substring((currURL.lastIndexOf('/')+1),currURL.length);
    var siteID = pageName.substring((pageName.indexOf('_')+1),pageName.lastIndexOf('_'));
    if (siteID=="1019"){$('#siteSearch .txtMedium').attr('value','Cautare')}; 
	
	// Attaching lang and worldwide link to Utility
	if($("*", "#utilityNav .topLinks").length != 0){$(".countryClass").append("|");}
	$("#utilityNav").appendTo("#mastHead .topLinks .onPage");
	$('.topLinks a').each(function(Index){
		if($(this).attr('href').indexOf('/worldwide_295_195131.html')!=-1){$(this).attr('class','worldWide').appendTo('#utilityNav')}
	});
		if($('#countryFlashWrapper')){
			$('.rightModule:first').attr('id','modulesx')
			$('.centerModule').each(function(e){$(this).attr('id','modules'+e+'');})
			equalHeight($('#modules0, #modules1'));
			equalHeight($('#modules2, #modules3'));
			}

});
// Equal Height 
	function equalHeight(group) {
		var tallest = 0;
		group.each(function() {
			var thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}

	// Mapping for geolocation cookie and country name
	var geo_cookie = new Array ( "AG", "AR", "AW", "BS", "BB", "BM", "BR", "CA", "KY", "CL", "CO", "DM", "EC", "SV", "GD", "GT", "HT", "HN", "JM", "MX", "PA", "PE", "PR", "KN", "LC", "TT", "US", "UY", "VE", "VI", "AT", "AZ", "BE", "BG", "CY", "CZ", "DK", "FI", "FR", "GE", "DE", "GR", "HU", "IE", "IT", "LI", "LU", "MT", "NL", "NO", "PL", "PT", "RO", "RU", "SK", "ES", "SE", "CH", "TR", "UA", "GB", "AU", "CN", "GU", "HK", "IN", "ID", "JP", "KR", "KZ", "MO", "MY", "NZ", "PK", "PG", "PH", "MP", "SG", "LK", "TW", "TH", "UZ", "VN", "BH", "IL", "KW", "LB", "OM", "QA", "SA", "AE", "EG", "KE", "ZA", "UG" );

	var country_names = new Array ( "Antigua & Barbuda", "Argentina", "Aruba", "Bahamas", "Barbados", "Bermuda", "Brazil", "Canada", "Cayman Islands", "Chile", "Colombia", "Dominica", "Ecuador", "El Salvador", "Grenada", "Guatemala", "Haiti", "Honduras", "Jamaica", "Mexico", "Panama", "Peru", "Puerto Rico", "St Kitts & Nevis", "St Lucia", "Trinidad", "United States", "Uruguay", "Venezuela", "Virgin Islands", "Austria", "Azerbaijan", "Belgium", "Bulgaria", "Cyprus", "Czech Republic", "Denmark", "Finland", "France", "Georgia", "Germany", "Greece", "Hungary", "Ireland", "Italy", "Liechtenstein", "Luxembourg", "Malta", "Netherlands", "Norway", "Poland", "Portugal", "Romania", "Russia",  "Slovakia", "Spain", "Sweden", "Switzerland", "Turkey", "Ukraine", "United Kingdom", "Australia", "China", "Guam", "Hong Kong", "India", "Indonesia", "Japan", "Korea", "Kazakhstan", "Macau", "Malaysia", "New Zealand", "Pakistan", "Papua New Guinea", "Philippines", "Saipan", "Singapore", "Sri Lanka", "Taiwan", "Thailand", "Uzbekistan", "Vietnam", "Bahrain", "Israel", "Kuwait", "Lebanon", "Oman", "Qatar", "Saudi Arabia", "United Arab Emirates", "Egypt", "Kenya", "South Africa", "Uganda" );

	// function to get country name as per the geolocation cookie
	function getCountryName (val) {
		var geocookie_len = geo_cookie.length;
		for(i=0;i<geocookie_len;i++)
		{
			if((readCookie("GEOLOCATION_COOKIE").substring(0,2)) == geo_cookie[i])
			{
				return country_names[i];
			}
		}
	}