$(document).ready(function(){
	$('ul.sf-menu').superfish();
	// Init News
	slides();	
	
	// Set some fonts
	fonts();		
	// BOF Make some shadows for bottom navigation titles
	shadows();
	// EOF Make some shadows for bottom navigation titles
	// Main navigation
	navi();
	// BOF - Init Login area stuff
	login();
	// EOF - Init Login area stuff

	// BOF Round some corners
	round_them();
	// EOF Round some corners
	// BOF Set some hover actions
	hover_them();
	// EOF Set some hover actions
	// BOF FAQ submenu
	$("#lnk-faq").click(function () {
	  $("#help-menu li ul.sub").toggle();
	});
	// EOF FAQ submenu
	// BOF Accordion
	jQuery('#faq, #pos').accordion({
		header: 'h3',
		active: false,
		autoheight: false,
	    alwaysOpen: false 
	});	
	// EOF Accordion
	// BOF PngFix
    $(document).ready(function(){ $(document).pngFix(); }); 
	// EOF PngFix
	
	$('a.sf-with-ul').mouseover(function() {
		$(this).css("color","#fff");
		$(this).css("background","#81b2da");
		$('ul.sf-menu li ul li a').each(function() {
			$(this).css("color","#fff");
			$(this).css("background","none");
		});
									 
	});
	$('#navigation').mouseout(function() {
		$('a.sf-with-ul').css("color","#003d7d");
		$('a.gr').css("color","#3f933d");
		$('a.sf-with-ul').css("background","none");
	});
});

// Free GMaps resources
window.onunload = googleUnload;
function googleUnload() {
	try
	  {
	  GUnload();
	  }
	catch(err)
	  {
	  }
}

function slides() {
	// Init News
	if ($('#slide1bg')) {
    	$('#slide1bg').flash({ src: '/media/flash/topads/voip-prices-bg.swf?'+Math.random(), width: 616, height: 222, wmode: 'transparent' }, { version: 8 } );
	}
	if ($('#slide1en')) {
		$('#slide1en').flash({ src: '/media/flash/topads/hotmax-en.swf?'+Math.random(), width: 616, height: 222, wmode: 'transparent' }, { version: 8 } );
	}

	if ($('#maxphone_prices')) {
		$('#maxphone_prices').flash({ src: '/media/flash/topads/voip-prices-maxphone-bg.swf?'+Math.random(), width: 616, height: 222, wmode: 'transparent' }, { version: 8 } );
	}
	if ($('#maxvox_prices')) {
		$('#maxvox_prices').flash({ src: '/media/flash/topads/voip-prices-maxvox-bg.swf?'+Math.random(), width: 616, height: 222, wmode: 'transparent' }, { version: 8 } );
	}

	var slidesoptions = {
	  firstname: "slides",
	  secondname: "showhere",
	  thirdname:"slides_display",
	  fourthname:"slides_button",
	  newsspeed:'20000',
	  imagedir:'/media/'
	}
	$.init_news(slidesoptions);
}

function fonts() {
	// Set some fonts
	if (hasCSS()) {
		$('.proinfo h3, .proinfo h3.hotmax, .proinfo h4, .intro h4, .td_left, h3.section').flash(
				{ 
					src: '/media/fonts/jfr.swf',
					wmode: 'transparent',
					flashvars: { css: ['* { color: #003D7D; text-align:center; }'].join(' ') }
				},
				{ version: 7 },
				function(htmlOptions) {
					htmlOptions.flashvars.txt = this.innerHTML;
					this.innerHTML = '<span>'+this.innerHTML+'</span>';
					var $alt = $(this.firstChild);
					htmlOptions.height = $alt.height();
					htmlOptions.width = $alt.width();
					$alt.addClass('alt');
					$(this)
						.addClass('flash-replaced')
						.prepend($.fn.flash.transform(htmlOptions));						
				}
			);
		$('.intro h3').flash(
				{ 
					src: '/media/fonts/jfr.swf',
					wmode: 'transparent',
					flashvars: { css: ['* { color: #003D7D; }'].join(' ') }
				},
				{ version: 7 },
				function(htmlOptions) {
					htmlOptions.flashvars.txt = this.innerHTML;
					this.innerHTML = '<span>'+this.innerHTML+'</span>';
					var $alt = $(this.firstChild);
					htmlOptions.height = $alt.height();
					htmlOptions.width = $alt.width();
					$alt.addClass('alt');
					$(this)
						.addClass('flash-replaced')
						.prepend($.fn.flash.transform(htmlOptions));						
				}
			);
			
		$('.intro span.red').flash(
				{ 
					src: '/media/fonts/jfr.swf',
					wmode: 'transparent',
					flashvars: { css: ['* { color: #ED1C24; }'].join(' ') }
				},
				{ version: 7 },
				function(htmlOptions) {
					htmlOptions.flashvars.txt = this.innerHTML;
					this.innerHTML = '<span>'+this.innerHTML+'</span>';
					var $alt = $(this.firstChild);
					htmlOptions.height = $alt.height();
					htmlOptions.width = $alt.width();
					$alt.addClass('alt');
					$(this)
						.addClass('flash-replaced')
						.prepend($.fn.flash.transform(htmlOptions));						
				}
			);

		$('.ptitle h2').flash(
				{ 
					src: '/media/fonts/jfr.swf',
					wmode: 'transparent',
					flashvars: { css: ['* { color: #F18E00; }'].join(' ') }
				},
				{ version: 7 },
				function(htmlOptions) {
					htmlOptions.flashvars.txt = this.innerHTML;
					this.innerHTML = '<span>'+this.innerHTML+'</span>';
					var $alt = $(this.firstChild);
					htmlOptions.height = $alt.height();
					htmlOptions.width = $alt.width();
					$alt.addClass('alt');
					$(this)
						.addClass('flash-replaced')
						.prepend($.fn.flash.transform(htmlOptions));						
				}
			);		
	}			
}

function shadows() {
	// BOF Make some shadows for bottom navigation titles
	if (hasCSS()) {
		$("h3.sh span").each(function(i){
			$(this).after('<br /><span class="shadow">'+$(this).text()+'</span>');
		});
	}
	// EOF Make some shadows for bottom navigation titles				
}

function navi() {
	// Main navigation
	$('#nav li').each(function () {
		$(this).mouseover(function() {
			$(this).addClass('over');
		});
		$(this).mouseout(function() {
			$(this).removeClass('over');
		});
	});
}

function login() {
	// BOF - Init Login area stuff
	$("#row-top").hide();
	$("#btn-login a").click(function () {
	  $("#row-top").toggle();
	});
	$("#btn-close").click(function () {
	  $("#row-top").hide();
	});
	// EOF - Init Login area stuff
}

function round_them() {
	$('.cc4, .round_row').corner({
	  tl: { radius: 5 },
	  tr: { radius: 5 },
	  bl: { radius: 5 },
	  br: { radius: 5 },
	  antiAlias: true,
	  autoPad: true,
	  validTags: ["div"] });
	$('.hold_intro, .submenu, .relations, .ptitle').corner({
	  tl: { radius: 5 },
	  tr: { radius: 5 },
	  bl: { radius: 5 },
	  br: { radius: 5 },
	  antiAlias: true,
	  autoPad: false,
	  validTags: ["div"] });
	$('.prev, .next, .btn-buy').corner({
	  tl: { radius: 5 },
	  tr: { radius: 5 },
	  bl: { radius: 5 },
	  br: { radius: 5 },
	  antiAlias: true,
	  autoPad: false});	
}

function hover_them() {
	//if ($('#new')) {
		$('.back-proinfo.new').mouseover(function () {
			$(this).children('.newbg').hide();
			$(this).children('.info').show();
			$(this).children('info').css('display', 'block');
		});
		$('.back-proinfo.new').mouseout(function () {
			$(this).children('.newbg').show();
			$(this).children('.info').hide();
		});
		$('.back-proinfo.new').mouseover(function () {
			$(this).children('.promobg').hide();
			$(this).children('.info').show();
			$(this).children('info').css('display', 'block');
		});
		$('.back-proinfo.new').mouseout(function () {
			$(this).children('.promobg').show();
			$(this).children('.info').hide();
		});
	//}
}

// Checks if CSS support is on
// Thanks David Kitchen (http://monc.se/kitchen/)
function hasCSS() {
	var _d = document.createElement('div')
	_d.id = 'css_test'
	$('body').append(_d)
	$('#css_test').css({width:'1px',height:'1px',display:'none'})
	var _v = ($('#css_test').width() != 1) ? false : true
	$('#css_test').remove()
	return _v
}

