$(document).ready(function() {
	if($('.imgTip').length > 0){
		$('a.imgTip').tinyTips('<div class=alerty></div>');
	}
	 
	if($('#panel_art').length > 0){
		$('#panel_art').jScrollPane({showArrows:true, scrollbarWidth:20, scrollbarMargin:10});
	}

	$(".l_cz_cm_box").click(function(){
		ajax_go('/gielda/dzial_' + $(this).children().attr('rel') + '_0.html?rand=' + new Date().getTime());
		$(this).addClass("l_cz_cm_boxWybrany");
	});
	
	$('#l_cz_form').submit(function(){
		ajax_go('/gielda/axsearch.html?rand=' + new Date().getTime() + '&key=' + $("#l_cz_szukaj_text").val());
		return false;
	});
	   
	$(".input_focus").focusin(function(){
		if($(this).val() == $(this).attr("title")){
			$(this).val('');
		}
	});
	
	$(".input_focus").focusout(function(){
		if($(this).val() == ''){
			$(this).val($(this).attr("title"));
		}
	});
	
	$(".btn_submit").click(function(){
		var field = $(this).attr("src");
		if($("#" + field).val() == $("#" + field).attr("title")){
			$("#" + field).val('');
		}
	});

	if($('marquee').length > 0){

		$(function(){
			$('div.demo marquee').marquee('pointer').mouseover(function () {
			    $(this).trigger('stop');
			}).mouseout(function () {
			    $(this).trigger('start');
			}).mousemove(function (event) {
			    if ($(this).data('drag') == true) {
			        this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
			    }
			}).mousedown(function (event) {
			    $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
			}).mouseup(function () {
			    $(this).data('drag', false);
			});
		});
	}
    
    $(".ns_click").click(function(){
    	$(".ns_click").removeClass('ns_menu_aktywne');
    	$(this).addClass('ns_menu_aktywne');
    	$(".marquee").addClass("hide");
    	$(".nsmore").addClass("hide");
		var id = $(this).attr("id");
    	$("#s" + id).removeClass("hide");
    	$("#m" + id).removeClass("hide");
    });

    //$('#panel_art').live("myCustomEvent",jScrollPane({showArrows:true, scrollbarWidth:20, scrollbarMargin:10}));

	var links = document.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++) {
	  var rels = links[i].getAttribute("rel");
	  if (rels) {
	    var testpattern = new RegExp("external");
	    if (testpattern.test(rels)) {
	      links[i].onclick = function() {
	        return !window.open(this.href);  
	      }
	    }
	  }
	}
	
	//pasek newslettera
	if($.cookie("box_x_visible") == true || $.cookie("box_x_visible") == null){
		$("#bar_x").removeClass("hide_x");
		$("#bar").removeClass("hide_x");
		$("#bar_x").addClass("show_x");
		$("#bar").addClass("show_x");
	}else{
		$("#bar_x").addClass("hide_x");
		$("#bar").addClass("hide_x");
		$("#bar_x").removeClass("show_x");
		$("#bar").removeClass("show_x");
	}

	$("#x").live("click",function(){//hide
		$.cookie("box_x_visible",0,{domain:'portalspozywczy.pl', path: '/', expires: 30 });
		$("#bar_x").addClass("hide_x");
		$("#bar").addClass("hide_x");
		$("#bar_x").removeClass("show_x");
		$("#bar").removeClass("show_x");
	});

	$(".grmenu").click(function(){
		$(".grmenu").removeClass("selected");
		$(this).addClass("selected");
		$(".grtab").addClass("hide");
		var id = $(this).attr("rel");
		$("#" + id).removeClass("hide");
	});
	
	$(".grsmenu").click(function(){
		$(".grsmenu").removeClass("selected");
		$(this).addClass("selected");
		$(".grstab").addClass("hide");
		$("#" + $(this).attr("rel")).removeClass("hide");
	});

});

$('.alkored').live('click', function(){
	window.location = "http://www.portalspozywczy.pl/"
});

$('.alkoclose').live('click', function(){
	$.cookie('alkoCheck', 1, {domain:'portalspozywczy.pl', path: '/', expires: 30 });
	$('#axn').css('display','none');
});

$('.nlaxclose').live('click', function(){
	$('#axn').css('display','none')
});

$('.axnlsub').live('click', function(){
	emailadd();
});

$('#newsletterForm').live('submit', function(){
	emailadd();
	return false;
});

function emailadd(){
	var mail = $('#newsletterFormEmail').val();
	if (mail != 'Wpisz adres e-mail...'){
		$('#axnlerror').html('');
		if(mail.length > 0){
			$('#axstatus').css('display','none');
			$('.axloading').css('display','block');
			$.post('/axnewsletter.html?email=' + mail + "&rand=" + new Date().getTime(), function(data){
				$('#axnlerror').html(data);
				$('#axstatus').css('display','block');
				$('.axloading').css('display','none');
				if($('#axrd').length > 0){
					window.location.href = 'http://www.portalspozywczy.pl/newsletter/zapis.html';
				}
				if($('#axrdex').length > 0){
					window.location.href = 'http://www.portalspozywczy.pl/newsletter/informacja.html';
				}
			});
		}else{
			$('#axnlerror').html('<b class="red">Należy wpisać adres email!</b>');
		}
	}else{
		$('#axnlerror').html('<b class="red">Należy wpisać adres email!</b>');
	}
}

function bmk(){
	if (document.all) window.external.AddFavorite(location.href, document.title);
	else if (window.sidebar) window.sidebar.addPanel(document.title, location.href, "")
}

function wykrestab(page,menu){
document.getElementById('wykresf1').style.display = 'none';
document.getElementById('wmf1').className = '';
document.getElementById('wykresf2').style.display = 'none';
document.getElementById('wmf2').className = '';
document.getElementById('wykresf3').style.display = 'none';
document.getElementById('wmf3').className = '';
document.getElementById(page).style.display = 'block';
document.getElementById(menu).className = 'current';
}
function newpopu(ovisible, ohidden, olink, ounlink){
document.getElementById(ohidden).style.visibility = 'hidden';
document.getElementById(ohidden).style.display = 'none';
document.getElementById(ovisible).style.visibility = 'visible';
document.getElementById(ovisible).style.display = 'block';
document.getElementById(olink).className = 'menu_u';
document.getElementById(ounlink).className = 'menu';
}
function cleartext(object,text){
ob = document.getElementById(object);
if (ob.value == text)
	ob.value = '';
else if (ob.value == '')
	ob.value = text;
}
function offerpopu(page,menu){
document.getElementById('tender').style.display = 'none';
document.getElementById('tendermen').className = 'float';
document.getElementById('work').style.display = 'none';
document.getElementById('workmen').className = 'float';
document.getElementById('training').style.display = 'none';
document.getElementById('trainingmen').className = 'float';
document.getElementById('invest').style.display = 'none';
document.getElementById('investmen').className = 'float';
document.getElementById('deb').style.display = 'none';
document.getElementById('debmen').className = 'float';
document.getElementById('komun').style.display = 'none';
document.getElementById('komunmen').className = 'float';
document.getElementById(page).style.display = 'block';
document.getElementById(page).className = document.getElementById(page).className.replace(/\bhide\b/,'')
document.getElementById(menu).className = 'float active';
}

function ftabs(page){
	document.getElementById('transf1').style.display = 'none';
	document.getElementById('transf2').style.display = 'none';
	document.getElementById(page).style.display = 'block';
}
$(function(){
// this initialises the demo scollpanes on the page.
});

function ajax_go(url){
	$('#l_cz_contentList').addClass("axloader");
	$("#l_cz_contentList").html('');
	$(".l_cz_cm_box").removeClass("l_cz_cm_boxWybrany");
	$.get(url, function(data){
		$('#l_cz_contentList').removeClass("axloader");
		$('#l_cz_contentList').html(data);
		$('#panel_art').jScrollPane({showArrows:true, scrollbarWidth:20, scrollbarMargin:10});
	});
}

//tinytip do alertow
(function(a) {
	a.fn.tinyTips = function(b) {
		var c = '<div class="tinyTip">&nbsp;</div>';
		var d = 300;
		var e;
		var f;
		a(this).hover(function() {
			a("body").append(c);
			e = a("div.tinyTip");
			e.hide();
			if (b === "title") {
				var g = a(this).attr("title")
			} else {
				if (b !== "title") {
					var g = b
				}
			}
			a(".tinyTip").html(g);
			f = a(this).attr("title");
			a(this).attr("title", "");
			var j = e.height() + 1;
			var h = (((e.width() - 10) / 2)) - (a(this).width() / 2);
			var k = a(this).offset();
			var i = k;
			i.top = k.top - j;
			i.left = k.left - h;
			e.css("position", "absolute").css("z-index", "1000");
			e.css(i).fadeIn(d)
		}, function() {
			a(this).attr("title", f);
			a("div.tinyTip").fadeOut(d, function() {
				a(this).remove()
			})
		})
	}
})(jQuery);
