var cartVisible = false;
var config = {    
	over: noaction,    
	timeout: 800, 
	out: hideLanguage 
};

$(function(){
	/*$('#Toolbar .Cart').click(function(){
		if ($(this).hasClass('Current')==false) {
			$(this).addClass('Current');
			showCartlist();
		} else {
			$(this).removeClass('Current');
			showCartlist();
		}
	});
	
	$('#Cartlist .Close').click(function(){
		showCartlist();
		$('#Toolbar .Cart').removeClass('Current');
	});*/
	
	$('#Language').mouseover(function() {
		showLanguage();
	}).mouseout(function(){
		hideLanguage();
	});

	//$("#Language").hoverIntent(config);
	//$('#Language').pngFix();
	
	$(window).scroll(function () {
		if($(window).scrollTop()>=1) {
			$('#Header').css('box-shadow','0 0 3px #1f1f1f');
		}else{
			$('#Header').css('box-shadow','0 0 0 #1f1f1f');
		}
	});
});

function noaction() {}

function showLanguage() {
	$('#Language .CurrentLang a').addClass('Current');
	$('#Language ul').show();
}

function hideLanguage() {
	$('#Language .CurrentLang a').removeClass('Current');
	$('#Language ul').hide();
}

/*function showCartlist() {
	$('#Cartlist').slideToggle({duration: 150, easing: 'easeOutCubic'});
}

function addCartlist() {
	$('#Cartlist').slideDown({duration: 150, easing: 'easeOutCubic'}).delay(1000).slideUp({duration: 150, easing: 'easeOutCubic'});
}*/

function epaperShow(act) {
	if ($('#Toolbar .Epaper').hasClass('Current')==false) {
		$('#Toolbar .Epaper').addClass('Current');
		$('#Epaper').fadeIn(300);
		$('select').css({ visibility: 'hidden' });
	} else {
		$('#Toolbar .Epaper').removeClass('Current');
		$('#Epaper').fadeOut(300);
		$('select').css({ visibility: 'visible' });
	}
}

function epaperHide(act) {
	$('#Toolbar .Epaper').removeClass('Current');
	$('#Epaper').fadeOut(300);
	$('select').css({ visibility: 'visible' });
}

function Subscribe(act) {
	$.ajax({
		url: '/lib/php/epaper.ajax.php',
		data: $('#Subscribe').serialize()+'&act=subscribe',
		success: function(msg){
			alert(msg);
		}
	});
}

function Unsubscribe(act) {
	$.ajax({
		url: '/lib/php/epaper.ajax.php',
		data: $('#Unsubscribe').serialize()+'&act=unsubscribe',
		success: function(msg){
			alert(msg);
		}
	});
}

$.ajaxSetup({
	beforeSend: function(xhr) {
		var currentURL = document.location.href;
		if( currentURL.lastIndexOf( "?" ) >= 0 ) {
			currentURL = currentURL.substr( 0, currentURL.lastIndexOf( "?" ) );
		}
		xhr.setRequestHeader("Referer", currentURL );
	},
	global: true,
	type: "POST"
});

function ajax(aurl,adata,aid) {
	$.ajax({
		url: aurl,
		data: adata,
		success: function(msg){
			$(aid).html(msg);
		}
	});
}

function videoShow(cat,id,country,title) {
	var _top = ($(window).height()-490)/2-$(window).height()*0.05+$(document).scrollTop();
	var _topIE6 = ($(window).height()-536)/2;
	if($.browser.msie && $.browser.version.substr(0,3)=="6.0") {
		$('#Videoclip .Frame').css({ top: _topIE6+'px' });
	} else {
		$('#Videoclip .Frame').css({ top: _top+'px' });
	}
	$('select').css({ visibility: 'hidden' });
	$('#Videoclip').fadeIn(100, function() {
		$('#Videoclip .Frame').css({ visibility: 'visible' });
		$('#Videoclip .Frame').animate({width:"730px", height:"445px", marginLeft:"-365px"}, 500, function() {
			$('#Videoclip .Content').css({width:"720px", height:"435px" });
			$.ajax({
				url: '/lib/php/videoplayer.php',
				data: 'cat='+cat+'&id='+id+'&country='+country+'&title='+title,
				success: function(msg){
					$("#Videoclip .Content").html('').html(msg);
					if(country!='CN'){
						$.getScript('http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4dc8957409134b22&domready=1', function() {
							addthis.init();
							addthis.toolbox(".addthis_toolbox");
						});
					}
				}
			});
			$('.Close', this).slideDown(500, function() {
				$('#Videoclip .Content').css({ visibility: 'visible' });
				//VideoJS.setupAllWhenReady();
			});
		});
	});
}

function videoHide(act) {
	$("#Videoclip .Content").html('')
	$('#Videoclip .Content').css({ visibility: 'hidden', width:"0px", height:"0px" });
	$('#Videoclip .Frame').css({ visibility: 'hidden', width:"200px", height:"200px", marginLeft:"-100px" });
	$('#Videoclip').fadeOut(400, function() {
		$('select').css({ visibility: 'visible' });
		$('.Close', this).hide();
	});
}

var timerAlert;
function alertBuilder(msg) {
	$("#AlertWindow .Msg td").html(msg);
	
	if (timerAlert) {
		clearTimeout(timerAlert);
	}
	$('#AlertWindow').fadeIn(100);
	timerAlert = setTimeout(function() {
		$('#AlertWindow').fadeOut(100)
	}, 1500)
}

function $import(path, type){
	if (type == "css") {
		document.write("<" + "link href=\"" + path + "\" rel=\"stylesheet\" type=\"text/css\"></" + "link>");
	} else {
		document.write("<" + "script src=\"" + path + "\"></" + "script>");
	}
}
