var _loading = '<div align="center" style="padding: 10px"><img src="/images/loading.gif" alt="" border="0" /></div><br />';

(function($,c,b){$.map("click dblclick mousemove mousedown mouseup mouseover mouseout change select submit keydown keypress keyup".split(" "),function(d){a(d)});a("focusin","focus"+b);a("focusout","blur"+b);$.addOutsideEvent=a;function a(g,e){e=e||g+b;var d=$(),h=g+"."+e+"-special-event";$.event.special[e]={setup:function(){d=d.add(this);if(d.length===1){$(c).bind(h,f)}},teardown:function(){d=d.not(this);if(d.length===0){$(c).unbind(h)}},add:function(i){var j=i.handler;i.handler=function(l,k){l.target=k;j.apply(this,arguments)}}};function f(i){$(d).each(function(){var j=$(this);if(this!==i.target&&!j.has(i.target).length){j.triggerHandler(e,[i.target])}})}}})(jQuery,document,"outside");

var checkReg = function() {

	if (!$('#email').val() || $('#email').val() == " ") {
		//FillDiv('username_alert', '<img src="images/warning_small.png" alt="" border="0" />');
		//alert('Az E-mail cím mező kitöltése kötelező!');
		$('#email').focus();
		$('#email').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/alert_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
		return false;

	} else {
		$('#email').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/ok_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
	} 
	
	if (!$('#password').val() || $('#password').val() == " ") {
		//FillDiv('username_alert', '<img src="images/warning_small.png" alt="" border="0" />');
		$('#password').focus();
		$('#password').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/alert_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
		return false;
	} else {
		$('#password').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/ok_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
	} 
	
	if (!$('#password2').val() || $('#email').val() == " ") {
		//FillDiv('username_alert', '<img src="images/warning_small.png" alt="" border="0" />');
		$('#password2').focus();
		$('#password2').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/alert_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
		return false;

	} else {
		$('#password2').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/ok_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
	} 
	
	if ($('#password').val() != $('#password2').val()) {
		//FillDiv('username_alert', '<img src="images/warning_small.png" alt="" border="0" />');
		$('#password').focus();
		$('#password').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/alert_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
		$('#password2').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/alert_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
		return false;

	} else {
		$('#password').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/ok_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
		$('#password2').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/ok_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
	}

	if (!$('#fname').val() || $('#fname').val() == " ") {
		//FillDiv('username_alert', '<img src="images/warning_small.png" alt="" border="0" />');
		//alert('Az E-mail cím mező kitöltése kötelező!');
		$('#fname').focus();
		$('#fname').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/alert_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
		return false;

	} else {
		$('#fname').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/ok_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
	} 

	if (!$('#lname').val() || $('#lname').val() == " ") {
		//FillDiv('username_alert', '<img src="images/warning_small.png" alt="" border="0" />');
		//alert('Az E-mail cím mező kitöltése kötelező!');
		$('#lname').focus();
		$('#lname').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/alert_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
		return false;

	} else {
		$('#lname').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/ok_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
	}
	
	var str = $('#register').serialize();
	$('#register_div').html('<br /><div align="center" style="padding: 20px 100px 20px 100px"><img src="/images/loading.gif" alt="" border="" /></div>');

	$.ajax({
		type: 'POST',
		url: '/modules.php?module=profile&file=regisztracio',
		data: str,
		success: function(data) {
			$('#register_div').html(data);
		}
	});

	return false;
}

var doLogin = function() {

	if (!$('#login_email').val() || $('#login_email').val() == " ") {
		//FillDiv('username_alert', '<img src="images/warning_small.png" alt="" border="0" />');
		//alert('Az E-mail cím mező kitöltése kötelező!');
		$('#login_email').focus();
		$('#login_email').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/alert_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
		return false;

	} else {
		$('#login_email').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/ok_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
	} 
	
	if (!$('#login_password').val() || $('#login_password').val() == " ") {
		//FillDiv('username_alert', '<img src="images/warning_small.png" alt="" border="0" />');
		$('#login_password').focus();
		$('#login_password').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/alert_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
		return false;
	} else {
		$('#login_password').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/ok_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
	} 
	
	var str = $('#loginform').serialize();
	$('#login').html('<br /><div align="center" style="padding: 20px 100px 20px 100px"><img src="/images/loading.gif" alt="" border="" /></div>');

	$.ajax({
		type: 'POST',
		url: '/modules.php?module=profile&file=login',
		data: str,
		success: function(data) {
			$('#login').html(data);
		}
	});

	return false;
}

function LoadNews(cid) {
	$('#index_news_ajax').html(_loading);
	$.get('/modules/news/include/index_ajax.php?cid='+cid, function(data) {
		$('#index_news_ajax').html(data);
	});
}

var pager = 0;
function LoadNext() {
	//$('#index_news_ajax').html(_loading);
	
	pager += 5;

	$.get('/modules/news/include/pager.php?1243&start='+pager, function(data) {
		$( "#index_news_ajax" ).toggle( 'slide', { direction: "left" }, 500 );
		$('#index_news_ajax').html(data);
		$( '#index_news_ajax' ).toggle( 'slide', { direction: "right" }, 500 );
	});
}

function LoadPrev() {

	if (pager >= 0) {

		//$('#index_news_ajax').html(_loading);

		pager -= 5;

		if (pager >= 0) {
			$.get('/modules/news/include/pager.php?1243&start='+pager, function(data) {
				$( "#index_news_ajax" ).toggle( 'slide', { direction: "right" }, 500 );
				$('#index_news_ajax').html(data);
				$( '#index_news_ajax' ).toggle( 'slide', { direction: "left" }, 500 );
			});
		}
	}
}

var newPassword = function() {

	if (!$('#email').val() || $('#email').val() == " ") {
		//FillDiv('username_alert', '<img src="images/warning_small.png" alt="" border="0" />');
		//alert('Az E-mail cím mező kitöltése kötelező!');
		$('#email').focus();
		$('#email').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/alert_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
		return false;

	} else {
		$('#email').css( {"border": "2px solid #ccc", "background-image": "url(/templates/aktrecords/images/ok_small.png?333)" ,"background-position": "right 2px","background-repeat": "no-repeat"} );
	} 
	
	var str = $('#register').serialize();
	$('#login').html('<br /><div align="center" style="padding: 20px 100px 20px 100px"><img src="/images/loading.gif" alt="" border="" /></div>');

	$.ajax({
		type: 'POST',
		url: '/modules.php?module=profile&file=password',
		data: str,
		success: function(data) {
			$('#register_div').html(data);
		}
	});

	return false;
}


function LoadVinyl(cid) {
	$('#index_vinyl_ajax').html(_loading);
	$.get('/modules/webshop/include/index_ajax.php?cid=1', function(data) {
		$('#index_vinyl_ajax').html(data);
	});
}

var pager = 0;
function LoadNextVinyl() {
	//$('#index_news_ajax').html(_loading);
	
	pager += 5;

	$.get('/modules/webshop/include/index_ajax.php?cid=1&start='+pager, function(data) {
		$( "#index_vinyl_ajax" ).toggle( 'slide', { direction: "left" }, 500 );
		$('#index_vinyl_ajax').html(data);
		$( '#index_vinyl_ajax' ).toggle( 'slide', { direction: "right" }, 500 );
	});
}

function LoadPrevVinyl() {

	if (pager >= 0) {

		//$('#index_news_ajax').html(_loading);

		pager -= 5;

		if (pager >= 0) {
			$.get('/modules/webshop/include/index_ajax.php?cid=1&start='+pager, function(data) {
				$( "#index_vinyl_ajax" ).toggle( 'slide', { direction: "right" }, 500 );
				$('#index_vinyl_ajax').html(data);
				$( '#index_vinyl_ajax' ).toggle( 'slide', { direction: "left" }, 500 );
			});
		}
	}
}

function LoadClothing(cid) {
	$('#index_clothing_ajax').html(_loading);
	$.get('/modules/webshop/include/index_ajax.php?cid=2', function(data) {
		$('#index_clothing_ajax').html(data);
	});
}

var pager = 0;
function LoadNextClothing() {

	pager += 5;

	$.get('/modules/webshop/include/index_ajax.php?cid=2&start='+pager, function(data) {
		$( "#index_clothing_ajax" ).toggle( 'slide', { direction: "left" }, 500 );
		$('#index_clothing_ajax').html(data);
		$( '#index_clothing_ajax' ).toggle( 'slide', { direction: "right" }, 500 );
	});
}

function LoadPrevClothing() {

	if (pager >= 0) {

		pager -= 5;

		if (pager >= 0) {
			$.get('/modules/webshop/include/index_ajax.php?cid=2&start='+pager, function(data) {
				$( "#index_clothing_ajax" ).toggle( 'slide', { direction: "right" }, 500 );
				$('#index_clothing_ajax').html(data);
				$( '#index_clothing_ajax' ).toggle( 'slide', { direction: "left" }, 500 );
			});
		}
	}
}

var last = 0;

var Play = function(id, title, pid) {

	var track = 
	[
		{
			"url": "/content/webshop/items/"+id+".mp3?123"
		}
	];

	//$('#tooltip_p'+id).append('<div id="swagg-player"><div id="swagg-player-progress-wrapper"></div></div>');
	//$('#tooltip_p'+id).css({'display':'block'});
	//$("#playa").css({'display':'block'});
	$("#playa").slideDown("slow");
	$("#playa_title").html('');
	$("#playa_title").html(title);
	$('#swagg-player-progress-wrapper').html('');

		$('#swagg-player-controls').html('<a id="swagg-player-play-button" href="#">play</a> | <a href="javascript:Stop()">stop</a> | <a href="javascript:addToCart(\'addtocart_'+pid+'\', \''+pid+'\', \'1\');"> kosárba / buy</a> | <a href="index.php?page=webshop&subpage=details&id='+pid+'">adatlap / details</a>');

	SwaggLoader.loadSwagg({
		data: track, // '/modules/webshop/include/trackload.json.php?id='+id,		// REQUIRED - path to your songs file JSON
		playList: false,
		buttonHover: true,
		debug: true,
		html5Audio: false,
		autoPlay: true,
		onPlay: function(){

			$('.p'+last).html('<a href="javascript:;" onclick="Play('+last+')"><img src="/templates/aktrecords/images/arrow.png" alt="" border="0" /></a>');
			
			if ($('#p2'+last)) {
				//$('#tooltip_p'+last).css({'display':'none'});
				$('#p2'+last).html('<a href="javascript:;" onclick="Play2('+last+')"><img src="/images/play.png" alt="" border="0" /></a>');
			}

            $('.p'+id).html('<a href="javascript:;" onclick="Stop()"><img src="/templates/aktrecords/images/stop.png" alt="" border="0" /></a>');
			

			last = id;
        }
	});

}

var Play2 = function(id, title, pid) {

	var track = 
	[
		{
			"url": "/content/webshop/items/"+id+".mp3?123"
		}
	];

	$("#playa").slideDown("slow");
	$("#playa_title").html('');
	$("#playa_title").html(title);
	$('#swagg-player-progress-wrapper').html('');
	$('#swagg-player-controls').html('<a id="swagg-player-play-button" href="#">play</a> | <a href="javascript:Stop2()">stop</a> | <a href="javascript:addToCart(\'addtocart_'+pid+'\', \''+pid+'\', \'1\');"> kosárba</a> | <a href="index.php?page=webshop&subpage=details&id='+pid+'">adatlap</a>');
	
	SwaggLoader.loadSwagg({
		data: track, // '/modules/webshop/include/trackload.json.php?id='+id,		// REQUIRED - path to your songs file JSON
		playList: false,
		buttonHover: false,
		debug: true,
		html5Audio: false,
		autoPlay: true,
		onPlay: function(){

			$('#p2'+last).html('<a href="javascript:;" onclick="Play2('+last+')"><img src="/images/play.png" alt="" border="0" /></a>');
			if ($('.p'+last)) {
				$('.p'+last).html('<a href="javascript:;" onclick="Play('+last+')"><img src="/templates/aktrecords/images/arrow.png" alt="" border="0" /></a>');
			}
            $('#p2'+id).html('<a href="javascript:;" onclick="Stop2()"><img src="/images/stop.png" alt="" border="0" /></a>');
			last = id;
        }
	});

}

var Stop = function() {
	var swaggplayerapi = $('#swagg-player-data').data('api');
	swaggplayerapi.currentSong.data().stop();
	$("#playa").slideUp("slow");
	$('#swagg-player-progress-wrapper').html('');
	//$('#tooltip_p'+last).css({'display':'none'});
	$('.p'+last).html('<a href="javascript:;" onclick="Play('+last+')"><img src="/templates/aktrecords/images/arrow.png" alt="" border="0" /></a>');
}

var Stop2 = function() {
	var swaggplayerapi = $('#swagg-player-data').data('api');
	swaggplayerapi.currentSong.data().stop();
	$("#playa").slideUp("slow");
	$('#swagg-player-progress-wrapper').html('');
	$('#p2'+last).html('<a href="javascript:;" onclick="Play2('+last+')"><img src="/images/play.png" alt="" border="0" /></a>');
}

function addToWishList(id) {

	$.get('/modules/profile/module/checklogin.php', function(data) {

		if (data == "YES") {
			$.ajax({
				type: 'GET',
				url: '/modules.php?module=profile&file=wishlist&action=add&product_id='+id,
				success: function(data) {
					$('#wl_'+id).html(data);
				}
			});

			return false;
		} else {
			$.get('/modules/profile/include/login_ajax.php', function(data) { $.facebox(data) });
		}

	});
}

function removeWishList(id) {

	$.get('/modules/profile/module/checklogin.php', function(data) {

		if (data == "YES") {
			$.ajax({
				type: 'GET',
				url: '/modules.php?module=profile&file=wishlist&action=remove&product_id='+id,
				success: function(data) {
					$('#wl_'+id).html(data);
				}
			});

			return false;
		} else {
			$.get('/modules/profile/include/login_ajax.php', function(data) { $.facebox(data) });
		}

	});
}

function addToCart(obj, id, quantity) {

	var str = $('#'+obj).serialize();

	$.get('/modules/profile/module/checklogin.php', function(data) {

		if (data == "YES") {
			$.ajax({
				type: 'POST',
				url: '/modules.php?module=profile&file=cart&action=add&quantity='+quantity+'&id='+id,
				data: str,
				success: function(data) {
					if ($('#cart_'+id)) {
						$('#cart_'+id).css({'display':'block'});
						$('#cart_'+id).html(data);
						setTimeout('$("#cart_'+id+'").fadeOut(2000);', 1500);
					}
					$('#playa_console').css({'display':'block'});
					$('#playa_console').html('<br />'+data);
					setTimeout('$("#playa_console").fadeOut(2000);', 1500);
				}
			});

			return false;
		} else {
			$.get('/modules/profile/include/login_ajax.php', function(data) { $.facebox(data) });
		}

	});
}

function editCart(id) {
	var str = $('#cart_quantity_'+id).val();
	$.get('/modules.php?module=profile&file=cart&action=edit&product_id='+id+'&quantity='+str, function(data) {
		$('#console').html(data);
	});
}

function removeFromCart(id) {
	$.get('/modules.php?module=profile&file=cart&action=remove&product_id='+id, function(data) {
		$('#console').html(data);
	});
}
