var animationTime = 7000;
$(function() {

	//gallery mainpage - first because this script destroy fancybox i tooltip
	$(".galleryBeforeItems").scrollable({ size: 1, mousewheel: false, clickable: false }).circular();

	if(jQuery.fn.defuscate) { $(".obfuscated").defuscate(); }
	if(jQuery.fn.toggleVal) { $(".togvalue").toggleVal(); }
	if(jQuery.fn.tooltip) { $(".tool_page").tooltip({ track: true, delay: 0, showURL: false, showBody: " - ", fade: 250 }); }

	$("a.bl_").attr({"target":"_blank"});
	$(".historyBack").click(function(event) { event.preventDefault(); history.back(-1); });
	$("a.goto").click(function(event) { event.preventDefault(); var $tr = $(this.hash); $tr = $tr.length && $tr || $('#' + this.hash.slice(1));
		if ($tr.length) { $('html,body').animate({scrollTop: $tr.offset().top}, 1000); /*, 'bounceout'*/ } });
	
	$("a.favorite").click(function(event) {
		event.preventDefault();
		if (document.all) { window.external.AddFavorite(location.href, document.title); } 
		else if (window.sidebar) { window.sidebar.addPanel(document.title, location.href, ""); }
	});

	$("a.fancybox").fancybox({'overlvayShow':true, 'overlayColor':'#000', 'overlayOpacity':0.73, 'padding':0, 'imageScale':true, onComplete:banHide, onCleanup:banShow, 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'titlePosition': 'over' });

	//fontSize
	var cl = ".only_highlight"; var fSmin = 9; var fSmax = 16;
	var oFS = $(cl).css('font-size');
    $('.FontZ').click(function(event){ event.preventDefault(); $(cl).css('font-size', oFS); });
	$('.FontP').click(function(event){ event.preventDefault(); var size = parseInt($(cl).css('font-size')); if(size < fSmax) $(cl).css('font-size', (size+1)); });
	$('.FontM').click(function(event){ event.preventDefault(); var size = parseInt($(cl).css('font-size')); if(size > fSmin) $(cl).css('font-size', (size-1)); });

	$(".gcms_loading").fadeOut("slow");
	//$(cl).focus(function() { return false; }).noContext().rightClick(function() { return false; }).disableTextSelect();
	$('.add_comments').click(function() { $(this).hide(); $(".comments_fieldset").show("slow"); });



	//buttony
	//SwitchClass(["buttonSub", "buttonCan"]);

	
	/*-------- MAINPAGE --------*/
	setTimeout('$(".autoForm").submit();', 5000);
	$(".showPreload").prepend('<div class="background none"></div><div class="backgroundShow none"></div><div class="progress none"></div>');
	$(".showPreload .background, .showPreload .backgroundShow, .showPreload .progress").removeClass("none").hide(0);

	$(".blueMenuBg .blueMenu").lavaLamp({ fx: "backout", speed: 600, overcolor: {color: '#28587e'},outcolor: {color: '#ffffff'}, speedcolor:300, click:function(event) {
		event.preventDefault();
		showPreloadList();
		$.post(publicRootPath+publicTemplate+'/ajax.html?GSystemAjax=loadListMainpage', { listID: $("a", this).attr("rel"), crc: ""}, function(data){ $(".loadedModuleMainpage").html(data); hidePreloadList(); });
	} });

	$(".ListAllStartClean .blueMenu").lavaLamp({ fx: "backout", speed: 600, overcolor: {color: '#28587e'},outcolor: {color: '#ffffff'}, speedcolor:300 });
	
	$(".ModRel2").removeClass("none").hide();
	$(".blueMenuModule").lavaLamp({ fx: "backout", speed: 600, overcolor: {color: '#28587e'},outcolor: {color: '#ffffff'}, speedcolor:300, click:function(event) {
		event.preventDefault();
		$(".ModRel1, .ModRel2").hide();
		$(".ModRel"+$("a", this).attr("rel")).fadeIn("slow");

	} });


	$(".exModRel2").removeClass("none").hide();
	$(".exMenuModule").lavaLamp({ fx: "backout", speed: 600, overcolor: {color: '#28587e'},outcolor: {color: '#ffffff'}, speedcolor:300, click:function(event) {
		event.preventDefault();
		$(".exModRel1, .exModRel2").hide();
		$(".exModRel"+$("a", this).attr("rel")).fadeIn("slow");

	} });
	

	$(".violetMenuBg .blueMenu").lavaLamp({ fx: "backout", speed: 600, overcolor: {color: '#641c6b'},outcolor: {color: '#ffffff'}, speedcolor:300, click:function(event) {
		event.preventDefault();
		$(".violetMainScroll").hide();
		$(".violetMainScroll" + $("a", this).attr("rel")).show();
		$(".violetBoxEnd .morePhoto").attr({href: $(".LinkForMoreMainGallery"+$("a", this).attr("rel")).html()});
	} });
	$(".violetMainScroll2, .violetMainScroll3").hide();
	$(".violetBoxEnd .morePhoto").attr({href: $(".LinkForMoreMainGallery1").html()});
	


	$(".topSubMenu").lavaLamp({ fx: "backout", speed: 600, overcolor: {color: '#2a4c01'},outcolor: {color: '#2a4c01'}, speedcolor:300 });
	$("#galMScrollable").scrollable({ size: 2, vertical: true, mousewheel: false, circular: true, easing: 'swing' }).autoscroll(7000).circular().navigator({navi:'.tabsNaviMain'});
	
	$(".recomendedCompanyPos").each(function() {
		if($(this).hasClass("none")) { $(this).removeClass("none").hide(0); }
	});
	setTimeout("recomendedContent()", animationTime);


	
	$(".topMenuSubGlobal").each(function(){
		if($(this).hasClass("none")) {
			$(this).removeClass("none").hide(0);
		}
	});
	$(".topMenu").lavaLamp({ fx: "backout", speed: 600, overcolor: {color: '#2a4c01'},outcolor: {color: '#ffffff'}, speedcolor:300, 
		click: function(event) {
			event.preventDefault();
			$(".topMenuSubGlobal").fadeOut("fast");
			$(".topMenuRel"+$("a", this).attr("rel")).fadeIn("normal");
		}
	});
	$(".recomendedCompanyPos").hover(function(){ $(this).addClass("recomendedCompanyPosAct"); }, function() { $(this).removeClass("recomendedCompanyPosAct") });

	$(".aImgExch").css({opacity:0.6});
	$(".opacity30").css({opacity:0.3});
	

	$(".tagsTablTag a, .tagsTablTagBig a, .tagsTablTagN a").each(function() {
		$(this).css({"font-size": $(this).attr("rel")+"%"});
	});
	$(".searchButton").click(function() { $("#searchForm").submit(); });


	//panel
	$(".loginPanel").removeClass("none").hide(0);
	$(".loginUser").click(function(event) { 
		event.preventDefault();
		$(".loginPanel").show("fast"); 
	});
	$(".loginPanelTitle").click(function(event) { event.preventDefault(); $(".loginPanel").hide("normal"); });

	$(".newsletterAddButton").click(function(event) { event.preventDefault(); $('#newsletterOption').val('add'); if($('#newsletterInput').val().length > 3) {$('#newsletterForm').submit();} });
	$(".newsletterDeleteButton").click(function(event) { event.preventDefault(); $('#newsletterOption').val('delete'); if($('#newsletterInput').val().length > 3) {$('#newsletterForm').submit();} });


	//ecard
	$("#galScrollable").scrollable({size: 1, clickable: false, onSeek: function() {
		var page = this.getPageIndex() + 1;
		$(".counter").html(page+"/"+$(".counterAll").html());
    }}).circular();

	$(".ecardSMenuUl").lavaLamp({ fx: "backout", speed: 600, overcolor: {color: '#28587e'},outcolor: {color: '#ffffff'}, speedcolor:300, 
		click: function(event) {
			event.preventDefault();
			$(".ecardSMenuUlRel").fadeOut(0);
			$(".ecardSMenuUlRel"+$("a", this).attr("rel")).fadeIn("normal");
		}
	});
	$(".ecardSMenuUlD").lavaLamp({ fx: "backout", speed: 600, overcolor: {color: '#28587e'},outcolor: {color: '#ffffff'}, speedcolor:300, 
		click: function(event) {
			event.preventDefault();
			var rel = $("a", this).attr("rel");
			$(this).parent().removeClass("ecardDescStartSecond ecardDescStartLast");
			if (rel==2) {
				$(this).parent().addClass("ecardDescStartSecond");
			} else if (rel==3) {
				$(this).parent().addClass("ecardDescStartLast");
			}
			$(".relEcardAll").fadeOut(0);
			$(".relEcardDesc"+rel).fadeIn("normal");
		}
	});
	$(".ecardDescContent > div, .ecardGalleryContB > div").each(function() {
		if($(this).hasClass("none")) {
			$(this).removeClass("none").hide(0);
		}
	});
	$(".gallEcard").click(function(event) {
		event.preventDefault();
		showPreloadList();
		var src = $(this).attr("href").replace("/350/", "/350a/"); 
		var alt = $("img", this).attr("alt");
		var i = new Image();
		i.src = src; 
		i.onload = function() {
			$(".bigEcardPhoto img").attr({"src" : src, "alt" : alt}); 
			$(".bigEcardPhoto").attr({"href" : src.replace("/350a/", "/1000/"), "title" : alt});
			hidePreloadList();
		};
	});
	$(".buttonFavoriteNoWork").click(function(event) {
		event.preventDefault();
		$(this).fadeOut("slow");
		$(".favoriteInfo").removeClass("none").hide(0).fadeIn("slow");
	});




	//catalog
	$(".belsEcatSliding, .belsEcatSlide, .belsEcatContent, .belsEcatEnd, .belsEcatContentBig, .belsEcatEndBig").each(function() { if($(this).hasClass("none")) { $(this).removeClass("none").hide(); } });
	$(".arrowEcat, .ecatBelsLink, .arrowEcatS").click(function(event) {
		event.preventDefault();
		var global = $(this).parent().parent();
		var globalAll = $(this).parent().parent().parent();
		if($("div", global).eq(0).hasClass("hid")) {
			$("div", global).eq(1).fadeOut("fast").addClass("hid");
			$("div", global).eq(0).fadeIn("slow").removeClass("hid");
			$(".belsEcatContent, .belsEcatEnd, .belsEcatContentBig, .belsEcatEndBig", globalAll).fadeOut("slow").removeClass("hid");
		} else {
			$("div", global).eq(0).fadeOut("fast").addClass("hid");
			$("div", global).eq(1).fadeIn("slow").removeClass("hid");
			$(".belsEcatContent, .belsEcatEnd, .belsEcatContentBig, .belsEcatEndBig", globalAll).fadeIn("slow").removeClass("hid");
		}
	});
	$(".comaDivS, .comaDivE").height($(".comaDivDesc").height());


	//global
	$(".blueMenuBg .blueMenu, .violetMenuBg .blueMenu, .topSubMenu, .topMenu, .ecardSMenu").each(function() {
		if($("a", this).size() == 1) { $("li", this).eq(0).addClass("nnn"); } else { $("li", this).eq($("a", this).size()-1).addClass("nnn"); }
	});


	//dictionary
	$("td.yeslong").click(function(event) {
		event.preventDefault();
		showPreloadList();
		var el = $(this).next();
		$.post(publicRootPath+publicTemplate+'/ajax.html?GSystemAjax=loadDictionaryValue', { dictionaryID: $("a", this).attr("rel"), crc: ""}, function(data){ el.html(data); hidePreloadList(); });
	});


	//listitem
	$(".moreCategoryHide").hide();
	$(".showMoreCategoryHide").click(function(event) {
		event.preventDefault();
		if($(".moreCategoryHide").hasClass("showed")) {
			$(".moreCategoryHide").slideUp("slow").removeClass("showed");
		} else {
			$(".moreCategoryHide").slideDown("slow").addClass("showed");
		}
	});

	//exchange
	$(".exPhotLastItem .photoModGal").click(function(event) {
		event.preventDefault();
		showPreloadList();
		var src = $(this).attr("href"); 
		var i = new Image();
		i.src = src; 
		i.onload = function() {
			$(".exPhotBigItem img").attr({"src" : src}); 
			$(".exPhotBigItem a").attr({"href" : src.replace("/300/", "/1000/")});
			hidePreloadList();
		};
	});
	$(".exchButtonDelete").click(function(event) {
		event.preventDefault();
		if(AcceptAlert($(this).attr("title"))) {
			goToUrl($(this).attr("rel"));
		}
	});
	if($.browser.mozilla || $.browser.safari) {
		$(".regInput, .regInputP, .registerRegulations").css({'-moz-border-radius': '7px'});
	}


	//forum
	$(".forHover").hover(function() { $(this).addClass("forumHover"); }, function() { $(this).removeClass("forumHover"); });
	//emoticons
	//img scale < 500px width



	//editor
	$('.ckeditorP').each(function() {
		var sizeAll = { height: $(this).height() ? $(this).height() : 200 };
		$(this).ckeditor(function() {}, $.extend({}, configCKAll, configCKPublic, sizeAll));
	});
	$('.ckeditorPE').each(function() {
		var sizeAll = { height: $(this).height() ? $(this).height() : 200 };
		$(this).ckeditor(function() {}, $.extend({}, configCKAll, configCKPublicEmot, sizeAll));
	});

	//anoun
	$(".readMoreAnnoun").click(function(event) { event.preventDefault(); $(".announMore"+$(this).attr("rel")).removeClass("none"); $(".comaMore"+$(this).attr("rel")).addClass("none"); $(this).addClass("none"); });

	
	$("body").prepend('<a href="#fb" class="fbIcon"></a><div class="fbIconBox"><iframe src="//www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2FBajeczneWesele&amp;width=300&amp;height=300&amp;colorscheme=light&amp;show_faces=true&amp;border_color&amp;stream=false&amp;header=false&amp;appId=279086362101782" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:300px; height:300px;" allowTransparency="true"></iframe></div>');
	$(".fbIcon").hover(function() { $(".fbIconBox").animate({left:0}, 500); }, function() {});
	$(".fbIconBox").hover(function() { }, function() { $(this).animate({left:-300}, 500); });


});

function banHide() { $(".bnWithFlash").hide(); }
function banShow() { $(".bnWithFlash").show(); }
function goToUrl(url) { window.location.href = url; };
function SwitchClass(elements) { $.each(elements, function(index, item) { $("." + item).hover(function() { $(this).addClass(item + "Active"); }, function() { $(this).removeClass(item + "Active"); }); }); };
function showElement(ident) { if($.browser.mozilla || $.browser.safari) { $(ident).fadeIn("slow"); } else { $(ident).css({display:"block"}); }; };
function hideElement(ident) { if($.browser.mozilla || $.browser.safari) { $(ident).fadeOut("slow"); } else { $(ident).css({display:"none"}); }; };
function AcceptAlert(text) { return confirm(text); }

function showPreloadList() {
	var top = (($(".showPreload").height()/2)-50) > 250 ? 110 : (($(".showPreload").height()/2)-50);
	$(".showPreload .background").css({'width': $(".showPreload").width(), 'height': $(".showPreload").height()}).fadeIn("fast", function() { $(this).css({opacity:0.8}); });
	$(".showPreload .backgroundShow").css({'top': top, 'left': ($(".showPreload").width()/2)-65}).fadeIn("fast");
	$(".showPreload .progress").css({'top': top+30, 'left': ($(".showPreload").width()/2)-16}).fadeIn("normal");
}
function hidePreloadList() {
	$(".showPreload .background, .showPreload .backgroundShow, .showPreload .progress").fadeOut("slow");
}
function recomendedContent() {
	var el = $(".recomendedContent").find("div.recomendedCompanyPos");
	var showTime = 2500;
	
	var el1 = $(".recomendedContent").find("div.recomendedCompanyPos:visible");
	var el2 = $(".recomendedContent").find("div.recomendedCompanyPos:hidden");
	$(el1).fadeOut("fast");
	$(el2).fadeIn(showTime);

	setTimeout("recomendedContent()", animationTime);
}
function setAction(action, form) { $("#"+form+" .action").val(action); $("#"+form).submit(); }
function AcceptAlert(text) { return confirm(text); }

//CKEDITOR
var configCKAll = { resize_enabled  : false, entities : false, autoUpdateElement : true, entities_latin : false, entities_greek : false, entities_processNumerical : true };
var configCKPublic = {
	skin : 'kama', toolbar: [
		['Bold','Italic','Underline','-','TextColor','-','NumberedList','BulletedList'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','Link','Image'],['PasteFromWord']
	]
};
var configCKPublicEmot = {
	skin : 'kama', toolbar: [
		['Bold','Italic','Underline','-','TextColor','-','NumberedList','BulletedList'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','Link','Image'],['PasteFromWord'],['Smiley']
	]
};
