function initializeFancyBoxImages()
{
	jQuery("a.fancyBoxImage").fancybox({
		'zoomSpeedIn':	500,
		'zoomSpeedOut':	300,
		'overlayShow':	true,
		'hideOnContentClick': true
	});
}

function v()
{
	void(null);
}

function setDefaultText(hInput, sDefaultText)
{
	sOldText = jQuery(jInput).val();
	alert(sOldText);
}

function popup(mylink, windowname, width, height){
	if (!window.focus) {
		return true;
	}
	var href;
	if (typeof(mylink) == 'string') {
		href = mylink;
	} else {
	   href=mylink.href;
	}
	window.open(href, windowname, 'width='+width+',height='+height+',scrollbars=yes');
	return false;
}

function submitForm(sFormName)
{
	jQuery('#' + sFormName + 'Submit').hide();
	jQuery('#' + sFormName).submit();
}

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

/*** JQUERY ***/
jQuery.noConflict();
jQuery(document).ready(function() {
	externalLinks();
	if(jQuery("div.boxSmallGalleryAll").length > 0) { // sprawdzanie czy jest taki div - zeby nioe bylo bledow
		getSmallGallery(); // small gallery na prawa strone
	}
	if(jQuery("div.boxYoutubeAll").length > 0) { // sprawdzanie czy jest taki div - zeby nioe bylo bledow
		getRightYoutube(); // youtube na prawo
	}

	/*** FANCY BOX ***/
	initializeFancyBoxImages();
});

function initializeInputFocusEffect(sInputName, sText)
{
	if (!jQuery("input[name='" + sInputName + "']").attr('value')) {
		jQuery("input[name='" + sInputName + "']").attr('value', sText);
	}
	jQuery("input[name='"+sInputName+"']").focus(function() 
	{
		jQuery("input[name='"+sInputName+"']").attr('value','');
	});
	jQuery("input[name='"+sInputName+"']").blur(function()
	{
		if (!jQuery("input[name='"+sInputName+"']").attr('value')) {
			jQuery("input[name='"+sInputName+"']").attr('value', sText);
		}
	});
} 

/*** SMALL GALLERY ***/

var iLastSmallGalleryId = 0;

function getSmallGallery(iSmallGalleryId)
{
	iSmallGalleryId = (iSmallGalleryId) ? iSmallGalleryId : 0;
	if (iSmallGalleryId) {
		var divSmallGallery = jQuery( "div.galleryAjaxLoad");
	} else {
		var divSmallGallery = jQuery( "div.galleryAjaxLoadList");
	}
	jQuery.ajax({
		method: "get",url: "ajax/getSmallGallery.php",data: "iSmallGalleryId=" + iSmallGalleryId + "&random=" + Math.random(),
			beforeSend: function(){
				var divPicture = jQuery(".boxSmallGallery .galleryPicture");
				jQuery(divPicture).css('background-image','url()');
				toggleSmallGalleryNavigation(true);
			}, //show loading just when link is clicked
//			complete: function(){ jQuery("#loading").hide("fast");}, //stop showing loading when the process is complete
		success: function(html){ //so, if data is retrieved, store it in html
//				jQuery(".content").show("slow"); //animation
				jQuery(divSmallGallery).html(html); //show the html inside .content div
			toggleSmallGalleryCurrentLink();
			changeSmallGalleryPicture(iCurrentSmallGalleryPicture, false);
//			alert(iMaxSmallGalleryPicture);
			if (iMaxSmallGalleryPicture > 1) {// jak jest wiecej niz jedno zdjęcie
				toggleSmallGalleryNavigation(false);
			}
		}
	}); //close jQuery.ajax(
}

function changeSmallGalleryPicture(iCurrentPicture, bPrev)
{
//	alert('iCurrentPicture: ' +iCurrentPicture);

	iNewPicture = 0;
	if (bPrev) {
		iNewPicture = ((iCurrentPicture - 1) == -1) ? iMaxSmallGalleryPicture - 1 : iCurrentPicture - 1;
	} else {
		iNewPicture = ((iCurrentPicture + 1) >= iMaxSmallGalleryPicture) ? 0 : iCurrentPicture+1;
	}
	var divPicture = jQuery(".boxSmallGallery .galleryPicture");
	jQuery(divPicture).css('background-image','url(' + sPathToSmallGallery + aSmallGallery[iNewPicture] + ')');

	var spanCounter = jQuery("#smallGalleryCounter");
	jQuery(spanCounter).html((iNewPicture+1) + ' z ' + iMaxSmallGalleryPicture);

	iCurrentSmallGalleryPicture = iNewPicture;
//	alert('iNewPicture:: ' + iNewPicture);
}

function toggleSmallGalleryCurrentLink()
{

	var hrefLastCategory = jQuery("#smallGalleryLink_" + iLastSmallGalleryId);
	jQuery(hrefLastCategory).removeClass("linkActive");

	var hrefCurrentCategory = jQuery("#smallGalleryLink_" + iCurrentSmallGallery);
	jQuery(hrefCurrentCategory).addClass("linkActive");

	iLastSmallGalleryId = iCurrentSmallGallery;
}

function toggleSmallGalleryNavigation(bHide)
{
	var sState = (bHide) ? 'hidden' : 'visible';
	var aPrev = jQuery(".galleryPicture .prev");
	jQuery(aPrev).css('visibility', sState);

	var aNext = jQuery(".galleryPicture .next");
	jQuery(aNext).css('visibility', sState);
}

function showMoreSmallGalleries()
{
	var divMoreSG = jQuery(".moreSmallGalleries");
	jQuery(divMoreSG).show();

	var hrefMoreSG = jQuery(".moreSmallGalleriesHref");
	jQuery(hrefMoreSG).hide();
}

/*** END SMALL GALLERY ***/


/*** RIGHT YOUTUBE ***/

function getRightYoutube()
{
	var divRightYoutube = jQuery( "div.youtubeListAll");
//	var divRightYoutube = jQuery( "div#footer");
	jQuery.ajax({
		method: "get",url: "ajax/getRightYoutube.php",data: "test=" + "test" + "&random=" + Math.random(),
		beforeSend: function(){

		},
//			complete: function(){ jQuery("#loading").hide("fast");}, //stop showing loading when the process is complete
	success: function(html){ //so, if data is retrieved, store it in html
		jQuery(divRightYoutube).html(html); //show the html inside .content div
		changeRightYoutubeList(false);
		}
	}); //close jQuery.ajax(
}


function changeRightYoutubeList(bPrev)
{
	iNewList = 0;
	if (bPrev) {
		iNewList = ((iCurrentYoutubeList - 1) == -1) ? 0 : iCurrentYoutubeList - 1;
	} else {
		iNewList = ((iCurrentYoutubeList + 1) >= iMaxYoutubeList - 1) ? iMaxYoutubeList - 1 : iCurrentYoutubeList + 1;
	}

	var divLastList = jQuery("#youtubeList_" + iCurrentYoutubeList);
	jQuery(divLastList).hide();

	var divList = jQuery("#youtubeList_" + iNewList);
	jQuery(divList).show();

	iCurrentYoutubeList = iNewList;

//	alert(iNewList);
}

function changeRightYoutubeVideo(iYoutubeId)
{
	var divVideo = jQuery(".youtubeVideo");
	var iVideoLink = aRightYoutubes[iYoutubeId];

	jQuery(divVideo).html('<object type="application/x-shockwave-flash" width="290" height="235" data="http://www.youtube.com/v/' + iVideoLink + '"><param name="movie" value="http://www.youtube.com/v/' + iVideoLink + '" /><param name="wmode" value="transparent" /></object>');

	var divYoutubeName = jQuery(".boxYoutube .youtubeName");
	jQuery(divYoutubeName).html(aRightYoutubesNames[iYoutubeId]);

	//var divGalleryDesc = jQuery(".boxYoutube .youtubeDesc");
	//jQuery(divGalleryDesc).html('{$aRightYoutubes.smallGalleryDesc}');

}

function showRightYoutubeNavigation()
{
	var aPrev = jQuery(".youtubeBottom .prev");
	jQuery(aPrev).css('visibility','visible');

	var aNext = jQuery(".youtubeBottom .next");
	jQuery(aNext).css('visibility','visible');

}

/*** NEW USERS ***/

function getUsers(sTargetDiv, iPage, sSearchKey , iSearchValue, iType) // target div, strona, czego mo szukac, id tego szukania, typ ludzia
{
	sSearchKey = (sSearchKey != undefined) ? sSearchKey : '';
	iSearchValue = (iSearchValue != undefined) ? iSearchValue : '';
	iType = (iType != undefined) ? iType : 0;

	var divSmallGallery = jQuery('.' + sTargetDiv);
	jQuery.ajax({
		method: "get",url: "ajax/users/getUsers.php", data: "page=" + iPage + "&key=" + sSearchKey + "&value=" + iSearchValue + "&type=" + iType + "&random=" + Math.random(),
		beforeSend: function(){
			showHideNewUsersPreloader();
		}, //show loading just when link is clicked
//			complete: function(){ jQuery("#loading").hide("fast");}, //stop showing loading when the process is complete
		success: function(html){ //so, if data is retrieved, store it in html
			showHideNewUsersPreloader(true);
			jQuery(divSmallGallery).html(html); //show the html inside .content div
		}
	}); //close jQuery.ajax(
}

function showHideNewUsersPreloader(bHide)
{
	if (bHide == 'undefined') {
		bHide = false;
	}

	var iDivContentHeight = jQuery("div.newUsers").height();
//		alert('iDivContentHeight: ' + iDivContentHeight);
	var divPreloader = jQuery( "div.preloaderApla");
	jQuery(divPreloader).height(iDivContentHeight);
	if (!bHide) {
		jQuery(divPreloader).show();
	} else {
		jQuery(divPreloader).hide();
	}
}


function showHidePreloader(sTargetDiv, bHide)
{
	if (bHide == 'undefined') {
		bHide = false;
	}
	var iDivContentHeight = jQuery('div.' + sTargetDiv).height();
	var divPreloader = jQuery('div.preloaderApla_' + sTargetDiv);
	jQuery(divPreloader).height(iDivContentHeight);
	if (!bHide) {
		jQuery(divPreloader).show();
	} else {
		jQuery(divPreloader).hide();
	}
}

/*** COMMENTS ***/

function getComments(sTargetDiv, iPage, sSearchKey, iSearchValue) // target div, strona, czego mo szukac, id tego szukania
{
	var divComments = jQuery('.' + sTargetDiv);
	jQuery.ajax({
		method: "get",
		url: "ajax/comments/getComments.php",
		data: "page=" + iPage + "&key=" + sSearchKey + "&value=" + iSearchValue + "&random=" + Math.random(),
		beforeSend: function(){
			showHidePreloader(sTargetDiv);
		},
		success: function(html) {
			showHidePreloader(sTargetDiv,true);
			jQuery(divComments).html(html);
		}
	}); //close jQuery.ajax(
}

/*** END COMMENTS ***/

/*** PICTURES ***/

function getPictures(sTargetDiv, iPage, sSearchKey, iSearchValue, sTable) // target div, strona, czego mo szukac, id tego szukania
{
	sTable = (sTable != undefined) ? sTable : '';
	var divPictures = jQuery('.' + sTargetDiv);
	jQuery.ajax({
		method: "get",url: "ajax/pictures/getPictures.php",data: "page=" + iPage + "&key=" + sSearchKey + "&value=" + iSearchValue + "&sTable=" + sTable + "&sTarget=" + sTargetDiv + "&random=" + Math.random(),
		beforeSend: function(){
			showHidePreloader(sTargetDiv);
		}, // show loading just when link is clicked
//			complete: function(){ jQuery("#loading").hide("fast");}, //stop showing loading when the process is complete
		success: function(html) { //so, if data is retrieved, store it in html
			showHidePreloader(sTargetDiv,true);
			jQuery(divPictures).html(html); // show the html inside .content div
			initializeFancyBoxImages();
		}

	}); //close jQuery.ajax(
}





/*** RIGHT RATINGS ***/

var iCurrentRightRating = -1;
function showRightRatings(iId) {
	var divRightRatingOld = jQuery("#rightRankingsContent_" + iCurrentRightRating); 
	var divRightRatingHrefOld = jQuery("#rightRankingsHref_" + iCurrentRightRating); 
	
	if (divRightRatingHrefOld) {
		jQuery(divRightRatingOld).hide();	
		jQuery(divRightRatingHrefOld).removeClass("active");
	}
	var divRightRating = ("#rightRankingsContent_" + iId); 
	var divRightRatingHref = ("#rightRankingsHref_" + iId); 
	jQuery(divRightRating).show();
	jQuery(divRightRatingHref).addClass("active");
	iCurrentRightRating = iId;
	return false;
}


/*** TABS ***/
 
function showTabContent(sContent, iTabId, iId) 
{
	var divTabOld = jQuery("#" + sContent + "_" + iTabId); 
	var divTabHrefOld = jQuery("#" + sContent + "Href_" + iTabId); 
	
	if (divTabHrefOld) {
		jQuery(divTabOld).hide();	
		jQuery(divTabHrefOld).removeClass("active");
	}
	var divTab = jQuery("#" + sContent + "_" + iId); 
	var divTabHref = jQuery("#" + sContent + "Href_" + iId); 
	jQuery(divTab).show();
	jQuery(divTabHref).addClass("active");
	iTabSkaut = iId;
	return false;
}




/*** EVENTS ***/

function getEvents(sTargetDiv, iPage, sSearchKey, iSearchValue) // target div, strona, czego mo szukac, id tego szukania
{
	var divEvents = jQuery('.' + sTargetDiv);
	jQuery.ajax({
		method: "get",url: "ajax/events/getEvents.php",data: "page=" + iPage + "&key=" + sSearchKey + "&value=" + iSearchValue + "&sTarget=" + sTargetDiv + "&random=" + Math.random(),
		beforeSend: function(){
			showHidePreloader(sTargetDiv);
		}, // show loading just when link is clicked
//			complete: function(){ jQuery("#loading").hide("fast");}, //stop showing loading when the process is complete
		success: function(html) { //so, if data is retrieved, store it in html
			showHidePreloader(sTargetDiv,true);
			jQuery(divEvents).html(html); // show the html inside .content div
			initializeFancyBoxImages();
		}
	}); //close jQuery.ajax(
}








/*** END JQUERY ***/


