// JavaScript Document


$(document).ready (function () {
	/** bind menu **/
	$('.center-nav-item').each(function () {
			$(this)
				.parent()
				.hover (mm.onMouseOver, mm.onMouseOut);
	});
	
	
	$('#center').hover (function () {},
						function () {
							mm.switchBG('bg-defult');
							});
		
	$('.add').tooltip();	
	
	
	$('#add-video').click(function () {
			var id = $(this).attr('vid');
			$.fancybox({
				'autoDimensions': false,
				'width' : 640,
				'height' : 420,
				'href' : 'topvideoplay.php?id='+id,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'orig'	: $(this),
				'padding' : '0'
				}
			);
		});
		
		
	$('#gt-button').click(function () {
			$.fancybox({
				'autoDimensions': false,
				'width' : '100%',
				'height' : '100%',
				'href' : 'gt/loader.html',
				'type':'iframe',
				'padding' : '0'
				}
			);
		
		
		});
		
	SWFAddress.onChange = lm.onChange;
		
});



var lm = {
	
	isOpen:false,
	request:null,
	
	onChange:function () {
		
		var newPath = SWFAddress.getPathNames();
		
		if (newPath == "") {
			lm.closeLayer();
		}else{
			lm.switchLayers();
			
		}
		
		$('#ajax-loader')
						.css('background-image','url(images/loader.gif)')
						.html('');
		
		
		var parameters = '';
		if (SWFAddress.getParameterNames()) {
			for (var i = 0; i < SWFAddress.getParameterNames().length; i++) {
				parameters += '&' + SWFAddress.getParameterNames()[i] + '=' +SWFAddress.getParameter(SWFAddress.getParameterNames()[i]);
			}
		}
		
		if (newPath.toString().indexOf('.php') == -1)
			newPath += ".php";
				
		if (lm.request)
			lm.request.abort();
			
		lm.request = $.get (newPath,parameters,function (data) {
											$('#ajax-loader')
															.css('background-image','none')
															.html (data);
											lm.request = null;
											});
	},
	
	
	switchLayers:function () {
		if (!lm.isOpen) {
			lm.isOpen = true;
			$('#center-navi').fadeOut(mm.aniTime);
			$('#center-content').slideDown(mm.aniTime);
			mm.switchBG('bg-defult');
		}
		
	},
	
	
	closeLayer:function () {
		lm.isOpen = false;
		$('#center-navi').fadeIn(mm.aniTime);
		$('#center-content').slideUp(mm.aniTime);
	}
	
	
	
}



var mm = {
	
	
	aniTime:500,
	
	onMouseOver:function () {
		/** image swap **/
		$(this)
			.children('a')
			.children('img')
			.stop()
			.fadeTo(mm.aniTime, 0);
		
		
		$(this)
			.children('.sub-menu')
			.slideDown(mm.aniTime);
		
		mm.switchColor($(this).children('a').attr('logo'), true);
		mm.switchBG($(this).children('a').attr('bg'));
	},
	
	
	onMouseOut:function () {
		/** image swap **/
		$(this)
			.children('a')
			.children('img')
			.stop()
			.fadeTo(mm.aniTime, 1);
		
		 
		$(this)
			.children('.sub-menu')
			.slideUp(mm.aniTime);
		
		
		mm.switchColor($(this).children('a').attr('logo'), false);
		
	},
	

	switchColor:function (color, show) {
		
		if(color == "blue" && show == true) {
			$('#top-logos')
						.children('img')
						.stop()
						.fadeTo(mm.aniTime, 0);
			
						
			$('.add-desc')
						.stop()
						.animate({'color':'#7BA0CE'}, mm.aniTime);
						
		}
		
		
		
		if(color == "blue" && show == false) {
			$('#top-logos')
						.children('img')
						.stop()
						.fadeTo(mm.aniTime, 1);
						
					
			$('.add-desc')
						.stop()
						.animate({'color':'#C30011'}, mm.aniTime);
						
		}
		
	},
	
	
	switchBG:function (bg) {
	
		$('.bg-image[id!="'+bg+'"]')
									.fadeOut(mm.aniTime)
									.children('img')
									.removeClass('quality')
									.addClass('speed');
									
									
		$('#'+bg).fadeIn(mm.aniTime,function () {
			
			$(this)
				.children('img')
				.removeClass('speed')
				.addClass('quality');	
			
		});
		
	}
	
	
}



$.fn.tooltip = function () {
	
		$(this).hover (showTooltip,
					   function () {
						   	$('#tooltip')
									.stop()
									.fadeTo(mm.aniTime, 0,function () {
										$(this).css('display','none');
										});
									   
						   });
	
		function showTooltip () {

			var $target = $(this);
			
			var left = $target.offset().left;
			var top  = $target.offset().top;
			
			var text = $target.attr('tooltip');
			
			$('#tooltip-text').html(text);
			$('#tooltip-image').css('background-image','url('+$target.attr('image')+')');
			
			var theight = $('#tooltip').height();
			var twidth = $('#tooltip').width();
			
			$('#tooltip')
						.css({'left':left-twidth/4,'top':(top-theight),'display':'block'})
						.stop()
						.fadeTo(mm.aniTime,1);
			
		}
	
}






