
$(document).ready(function(){



	/* cyclePersons*/

	    $(".cyclePersons").jCarouselLite({
	    	auto: 5000,
	    	visible: 3,
	    	scroll: 1,
	    	btnNext: ".cyclePersonsButtonsRight",
	        btnPrev: ".cyclePersonsButtonsLeft"
	    });


	/* cycleNews*/
	$(function() {
	    $(".cycleNews").jCarouselLite({
	    	speed: 500,
	    	auto: 10000,
	    	visible: 1,
	    	scroll: 1,
	    	btnNext: ".cycleNewsButtonsRight",
	        btnPrev: ".cycleNewsButtonsLeft"
	    });
	});



	/* cycleUserActive*/
	$(function() {
	    $(".cycleUserBoxes").jCarouselLite({
	    	speed: 500,
	    	auto: null,
	    	visible: 3,
	    	scroll: 3,
	    	btnNext: ".cycleUserRight",
	        btnPrev: ".cycleUserLeft"
	    });
	});

		$(function() {
	    $(".cycleUserBoxes2").jCarouselLite({
	    	speed: 500,
	    	auto: null,
	    	visible: 3,
	    	scroll: 3,
	    	btnNext: ".cycleUserRight2",
	        btnPrev: ".cycleUserLeft2"
	    });
	});

	/* cycleUserArticle */
	$(function() {
		$(".cycleUserArticle").jCarouselLite({
			speed: 500,
			auto: null,
			vertical: true,
			visible: 3,
			scroll: 1,
			btnNext: ".cycleUserDown",
			btnPrev: ".cycleUserUp"
		});
	});

	/* cycleUserGallery */
	$(function() {
		$(".cycleUserGallery").jCarouselLite({
			speed: 1,
			auto: null,
			visible: 6,
			scroll: 1,
			btnNext: ".cycleUserRight",
			btnPrev: ".cycleUserLeft"
		});
	});


	$(function() {
		$(".cycleEditUserGallery").jCarouselLite({
			speed: 500,
			auto: null,
			visible: 3,
			scroll: 3,
			btnNext: ".cycleUserRight",
			btnPrev: ".cycleUserLeft"
		});
	});

	/*obsługa menu bez przeładowywania*/
	/*
	[ul li] wyróżnione ma mieć class="active" domyślnie element z 1 jest aktywny
	[ul] ma miec class="mbar" i id {np. 'xxx'}
 	[ul li a] musi miec id z [ul] z kolejnym numerem {np. 'xxx1' puzniej 'xxx2'}
	[div] ma miec klase jak ul id {'xxx'} i klase jak [ul li a] z przedrostkiem m {np. 'mxxx1' puzniej 'mxxx2'}


	<ul class="mbar" id="a">
		<li class="active"><a href="#toogle" id="a1">menu 1</a></li>
		<li><a href="#toogle" id="a2">menu 2</a></li>
	</ul>
	<div class="a ma1">tekst 1</div>
	<div class="a ma2">tekst 2</div>
	*/
	$.each( $(".mbar") , function(i,n) {
		var namelist=$(this).attr("id");
		$("."+namelist).hide();
		$(".m"+namelist+"1").show();
	});

	$(".mbar a").click(function(){
		{
			var namelist=$(this).parent().parent().attr("id");
			var normal=$(this).attr("id");
			if (namelist && normal)
			{
				$("#"+namelist).find("li").removeClass("active");
				$(this).parent().addClass("active");

				$("."+namelist).hide();
				$(".m"+this.id).show();

				return false;
			}
			else return true;
		}
	});

	//Aby dupny IE nadal elementom styl
	$("#menuA2").click(function(){setTimeout( function(){$('.cycleUserBoxes2').css('z-index','3')} , 1) });
	$("#boxMyMediaMenu3").click(function(){setTimeout( function(){$('#mboxMyMediaMenu3').css('z-index','3')} , 1) });
	$("#boxMyMediaMenu2").click(function(){setTimeout( function(){$('#mboxMyMediaMenu2').css('z-index','3')} , 1) });



	hs.graphicsDir = '/static/css/img/highslide/';

	writeBookmarkLink(document.URL, document.title);

});


function news_bar(dontShowNewsBar){

if (dontShowNewsBar) {
	dontShowNewsBar = "true";
} else {
	dontShowNewsBar = "false";
}

	$.ajax(
		{
			type:"POST",
			data:'&dontShowNewsBar='+dontShowNewsBar,
			dataType:"json",
			async: true,
			url: "/default-news_bar-ajaxnoredirect",
			success: function (json){

			},
			error: function (){

			}
		}
	);
}

function ecommerce(div_id)
{
	$.ajax(
	{
		type:"GET",
		dataType:"json",
		async: true,
		url: "/default-ecommerce-ajaxnoredirect",
		success: function (json){
			$("#"+div_id).html(json);
		},
		error: function (){

		}
	});
}


// funkcje dla dodawania do zakladek/ulubionych, znajduje sie w header
function createBookmarkLink(url, title) {

	try {
		if (window.sidebar) { // Mozilla Firefox Bookmark
			return window.sidebar.addPanel(title, url, "");
		} else if( window.external ) { // IE Favorite
			return window.external.AddFavorite( url, title);
		} else if(window.opera && window.print) { // Opera Hotlist
			return true;
		}
	} catch(err) {
		// do nothing
	}
	alert('Could not create a bookmark on your client.\n\nTo return to ' + title + ' you must manually create a bookmark to: \n' + url + '.');
}

function writeBookmarkLink(url, title) {
var anchor = $("#BookmarkLink");
	try {
		if (window.sidebar) { // Mozilla Firefox Bookmark
			$(anchor).html('<a href="javascript:createBookmarkLink(\'' + url + '\', \'' + title + '\')");">Dodaj do zakładek' + '</a>');
		} else if (window.external) { // IE Favorite
			$(anchor).html('<a href="javascript:createBookmarkLink(\'' + url + '\', \'' + title + '\')");">Dodaj do ulubionych' + '</a>');
		} else if (window.opera && window.print) { // Opera Hotlist
			$(anchor).html('<a rel="sidebar" href="' + url + '" title="' + title + '">Dodaj do zakładek' + '</a>');
		}
	} catch(err) {
		// do nothing
	}
	//$(anchor).html('To return to ' + title + ' create a bookmark to: <a style="color: white;" href="' + url + '">' + url + '</a>');
}

///////////////////////////////////////////////////////////////////////////////
// obsluga przycisku logowania
// jesli nie ma login postaci login@host.pl to koncowka pino.pl jest dodawana
function login_button_function()
{
	var new_login = $("#loginInput").val();
	if( new_login.indexOf('@') > 0 ){
		return true;
	}
	new_login = new_login + "@pino.pl";
	$("#loginInput").attr("value", new_login );
	return false;
}

function hideDefault(option) {
	if(option == 'title') // kliknieto title
	{
		if($("#commentFormTitle1").attr('value') == '- nagłówek komentarza -')
		{
			$("#commentFormTitle1").attr('value' , '')
		}
	}
	else // kliknieto description
	{
		if($("#commentFormDescription1").attr('value') == '- treść komentarza -')
		{
			$("#commentFormDescription1").attr('value' , '')
		}
		if($("#commentFormTitle1").attr('value') == '- nagłówek komentarza -')
		{
			$("#commentFormTitle1").attr('value' , '')
		}
	}
}

function StartCountDown(myDiv,myTargetDate,str)
{
	var dthen	= new Date(myTargetDate);
	var dnow	= new Date();
	ddiff		= new Date(dthen-dnow);
	gsecs		= Math.floor(ddiff.valueOf()/1000);
	CountBack(myDiv,gsecs,str);
}

function Calcage(secs, num1, num2)
{
	s = ((Math.floor(secs/num1))%num2).toString();
	if (s.length < 2)
	{
	s = "0" + s;
	}
	return (s);
}

function CountBack(myDiv, secs, str)
{
	if( typeof str == 'undefined' ) {
		str = '';
	}
	var DisplayStr;
	var DisplayFormat = "%%D%% Dni %%H%%:%%M%%:%%S%%";
	DisplayStr = DisplayFormat.replace(/%%D%%/g,	Calcage(secs,86400,100000));
	DisplayStr = DisplayStr.replace(/%%H%%/g,		Calcage(secs,3600,24));
	DisplayStr = DisplayStr.replace(/%%M%%/g,		Calcage(secs,60,60));
	DisplayStr = DisplayStr.replace(/%%S%%/g,		Calcage(secs,1,60));
	if(secs > 0)
	{
		document.getElementById(myDiv).innerHTML = str + ' ' + DisplayStr;
		setTimeout("CountBack('" + myDiv + "'," + (secs-1) + ", '"+str+"');", 990);
	}
	else
	{
		document.getElementById(myDiv).innerHTML = "Zakończone";
	}
}
