$(document).ready(function() {

	var phonedata = {
		IT : {
			text	:	"Supporto Telefonico",
			number	:	"+39 06452215681",
			imgpos	:	"0px -97px"
		},
		UK : {
			text	:	"Phone Support",
			number	:	"+44 1546471118",
			imgpos	:	"-40px -97px"
		},
		US : {
			text	:	"Phone Support",
			number	:	"+01 3239271093",
			imgpos	:	"-20px -97px"
		}
	};

	var phoneselectstate = 'opened';
	$("div.header").prepend('<div id="phonesupport"><div id="phonesupporttext"></div><div id="phoneselect" class="listclosed"><div id="phoneselectedcountry"></div><div id="phoneselectedflag"></div><div id="phonedropdownarrow"></div></div><div id="phonenumber"></div><br /><div id="phonedropdownlist" class="dropdownclosed"><span class="dropdownfooter"></span></div></div>');

	for (var k in phonedata) {
		$("#phonedropdownlist").prepend('<div class="dropdownitem" rel="' + k + '"><span class="dropdownitemcountry">' + k + '</span><span class="dropdownitemflag" style="background-position:' + phonedata[k]['imgpos'] + '"></span>&nbsp;</div>');
	}

	$(".dropdownitem").click(function(){
		$("#phoneselectedcountry").html($(this).attr('rel'));
		$("#phoneselectedflag").css("background-position",phonedata[$(this).attr('rel')]['imgpos']);
		$("#phonenumber").html(phonedata[$(this).attr('rel')]['number']);
		$("#phonesupporttext").html(phonedata[$(this).attr('rel')]['text']);
		$("#phoneselect").click();
	});

	$("#phoneselect").click(function(){
		phoneselectstate = phoneselectstate == 'opened' ? 'closed' : 'opened';
		$("#phoneselect").attr('class', 'list'+phoneselectstate);
		$("#phonedropdownlist").attr('class', 'dropdown'+phoneselectstate);
	});
	
	$("div[rel='IT']").click();
	
	// Live support image fix
	$("#live-support img").attr("src", "http://www.speedhosting.it/images/live_support.gif");
	$("#live-support2 img").attr("src", "http://www.speedhosting.it/images/live_support.gif");
	
	// buttons fix
	$("input[type='submit']").each(function(){
		$(this).replaceWith('<button type="submit" class="submitbutton"><span><span>' + $(this).attr("value") + '</span></span></button>');
	});
	$("input[type='reset']").each(function(){
		$(this).replaceWith('<button type="submit" class="resetbutton"><span><span>' + $(this).attr("value") + '</span></span></button>');
	});
	
	$("p[align='center']").each(function(){
		if($(this).html().replace('WHMCompleteSolution','') != $(this).html()){
			$(this).html('');
		};
	});
});

