function get(name){
	return document.getElementById(name);
}

$(document).ready(function(){	
			
	$(function(){
		if(get('scrollBar')){
			//$('#scrollBar').jScrollPane();
		}
		
		setAnimateScrollBar();
		$("#contactBox").hide();
		$("#reportBox").hide();
		var chosen = "";
		$("#fKategoria option:selected").each(function () {
			chosen = $(this).val();
	    });
	
		if(chosen > 0){
			var str = "";
	        $("#fKategoria option:selected").each(function () {
	              str += $(this).val();
				  $("#fSubKategoria").removeOption(/./);
	            });
			$("table#SFOkate2").hide();
			$('li.hideOne').animate({height: "30px"},300, function(){
				$('table#SFOkate2').fadeIn("normal");
			})
			if(str == 'all'){
				$('table#SFOkate2').fadeOut("normal", function(){
					$('li.hideOne').animate({height: "0px"},300, function(){
						$('li.hideOne').hide();
					});
				})
			}
			
			var lang;
			var ciacha = document.cookie.split(';');
			for(z=0; z<ciacha.length; z++){
				var tmp = ciacha[z].split('=');
				if(tmp[0] == ' baunet-lang'){
					lang  = tmp[1];
				}
			}
	
			$.ajax({
				type: "POST",
				url: "/javascript/load_subcats.php",
				data: "id_kat=" + str + "&lang=" + lang,
				success: function(obj){
				     var mainTab = obj.split("+");
					 for(i=0; i<mainTab.length; i++){
					 	var subTab = mainTab[i].split("|");
						$("#fSubKategoria").addOption(subTab[0], subTab[1]);
					 }
					 if(get('fKatValue').innerHTML){
					 	$("#fSubKategoria").selectOptions(get('fKatValue').innerHTML);
					 }else{
					 	 $("#fSubKategoria").selectOptions('all');
					 }
				}
			});
		}
		$('li.hideOne').hide();
		
		var aChosen = "";
		$("#aKategoria option:selected").each(function () {
			aChosen = $(this).val();
	    });
		
		if(aChosen > 0){
			var str = "";
	        $("#aKategoria option:selected").each(function () {
	              str += $(this).val();
				  $("#aSubKategoria").removeOption(/./);
	            });
			if (str != 'all') {
			
				var lang;
				var ciacha = document.cookie.split(';');
				for (z = 0; z < ciacha.length; z++) {
					var tmp = ciacha[z].split('=');
					if (tmp[0] == ' baunet-lang') {
						lang = tmp[1];
					}
				}
			
				$.ajax({
					type: "POST",
					url: "/javascript/load_subcats.php",
					data: "id_kat=" + str + "&lang=" + lang,
					success: function(obj){
						
						var mainTab = obj.split("+");
						for (i = 0; i < mainTab.length; i++) {
							var subTab = mainTab[i].split("|");
							$("#aSubKategoria").addOption(subTab[0], subTab[1]);
						}
						if (get('adChosen').innerHTML) {
							$("#aSubKategoria").selectOptions(get('adChosen').innerHTML);
						}
						else if(get('eSubKat').value){
							$("#aSubKategoria").selectOptions(get('eSubKat').value);
						}
						else {
							$("#aSubKategoria").selectOptions('all');
						}
					}
				});
			}
		}		
	});
	
	
		
	$("#showGalleryClk").click(function(){
      	$("#artContent").slideToggle("slow");
	});
	
	$("#showContactForm").hover(function(){
		$(this).addClass('lapka');
    }, function(){
		$(this).removeClass('lapka');
    });
	
	$("#showContactForm").click(function(){
      	$("#contactBox").slideDown("normal");
	});
	
	$("#showReportForm").hover(function(){
		$(this).addClass('lapka');
    }, function(){
		$(this).removeClass('lapka');
    });
	
	$("#showReportForm").click(function(){
      	$("#reportBox").slideDown("normal");
	});
	
	
	$("#showUserOfers").hover(function(){
		$(this).addClass('lapka');
    }, function(){
		$(this).removeClass('lapka');
    });
	
	$("#askLeasing").hover(function(){
		$(this).addClass('lapka');
    }, function(){
		$(this).removeClass('lapka');
    });
		
	$("#hideContactForm").hover(function(){
		$(this).addClass('lapka');
    }, function(){
		$(this).removeClass('lapka');
    });
	
	$("#hideContactForm").click(function(){
      	$("#contactBox").slideUp("normal");
	});
	
	$("#hideReportForm").hover(function(){
		$(this).addClass('lapka');
    }, function(){
		$(this).removeClass('lapka');
    });
	
	$("#hideReportForm").click(function(){
      	$("#reportBox").slideUp("normal");
	});
	
	$("#fKategoria").change(function(){
		var str = "";
        $("#fKategoria option:selected").each(function () {
              str += $(this).val();
			  $("#fSubKategoria").removeOption(/./);
            });
		$("table#SFOkate2").hide();
		$('li.hideOne').animate({height: "30px"},300, function(){
			$('table#SFOkate2').fadeIn("normal");
		})
		if(str == 'all'){
			$('table#SFOkate2').fadeOut("normal", function(){
				$('li.hideOne').animate({height: "0px"},300, function(){
					$('li.hideOne').hide();
				});
			})
		}
		
		var lang;
		var ciacha = document.cookie.split(';');
		for(z=0; z<ciacha.length; z++){
			var tmp = ciacha[z].split('=');
			if(tmp[0] == ' baunet-lang'){
				lang  = tmp[1];
			}
		}

		$.ajax({
			type: "POST",
			url: "/javascript/load_subcats.php",
			data: "id_kat=" + str + "&lang=" + lang,
			success: function(obj){
			     var mainTab = obj.split("+");
				 for(i=0; i<mainTab.length; i++){
				 	var subTab = mainTab[i].split("|");
					$("#fSubKategoria").addOption(subTab[0], subTab[1]);
				 }
				 $("#fSubKategoria").selectOptions('all');
			}
		});
	})
	
	$("#aKategoria").change(function(){
		var str = "";
        $("#aKategoria option:selected").each(function () {
              str += $(this).val();
			  $("#aSubKategoria").removeOption(/./);
            });
			
		if (str != 'all') {
			
			var lang;
			var ciacha = document.cookie.split(';');
			for(z=0; z<ciacha.length; z++){
				var tmp = ciacha[z].split('=');
				if(tmp[0] == ' baunet-lang'){
					lang  = tmp[1];
				}
			}
			
			$.ajax({
				type: "POST",
				url: "/javascript/load_subcats.php",
				data: "id_kat=" + str + "&lang=" + lang,
				success: function(obj){
					var mainTab = obj.split("+");
					for (i = 0; i < mainTab.length; i++) {
						var subTab = mainTab[i].split("|");
						$("#aSubKategoria").addOption(subTab[0], subTab[1]);
					}
					$("#aSubKategoria").selectOptions('all');
				}
			});
		}
	})
		
//	$("a[rel='facebox']").facebox();
	
	$("a[rel='facebox[gallery2]']").prettyPhoto({
			showTitle: false,
			allowresize: true	
	});
	
	$("a[rel='facebox2[gallery]']").prettyPhoto({
			showTitle: false,
			allowresize: true	
	});

	
	////$('a[rel*=facebox[gallery]]').facebox({
	//    next_image    : 'images/facebox/fast_forward.gif',
	//    play_image    : 'images/facebox/play.gif',
	//    pause_image   : 'images/facebox/pause.gif',
	//    prev_image    : 'images/facebox/rewind.gif'
	//}) 
	
	$('#actionBar').hide('fast');
	setSifr();
});

function setSifr()
{
/*	sIFR.prefetch({
    src: './javascript/cochin-7.swf', 
    highsrc: './javascript/cochin-8.swf'
  }, {
    src: './javascript/rockwell-7.swf', 
    highsrc: './javascript/rockwell-8.swf'
  });
  
  sIFR.compatMode = true;
  sIFR.activate();
  sIFR.replace({
    selector: 'h2.sifr1', 
    src: './javascript/cochin-7.swf', 
    highsrc: './javascript/cochin-8.swf',
    css: {
      '.sIFR-root' : { 'text-align': 'center', 'font-weight': 'bold' },
      'a': { 'text-decoration': 'none' },
      'a:link': { 'color': '#000000' },
      'a:hover': { 'color': '#CCCCCC' }
    },
    paddingTop: 20
  });*/
 // This is the preferred "named argument" syntax
	//sIFR.replaceElement(named({sSelector:"h2.sifr1", sFlashSrc:"./javascript/tradegothic.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:20, nPaddingBottom:20, sFlashVars:"textalign=center&offsetTop=6"}));

// This is the older, ordered syntax
//	sIFR.replaceElement("h5#pullquote", "tradegothic.swf", "#000000", "#000000", "#FFFFFF", "#FFFFFF", 0, 0, 0, 0);
//	sIFR.replaceElement("h2", "tradegothic.swf", "#000000", null, null, null, 0, 0, 0, 0);
//	sIFR.replaceElement("h4.subhead", "tradegothic.swf", "#660000", null, null, null, 0, 0, 0, 0);
//	sIFR.replaceElement("h3.sidebox","tradegothic.swf","#000000", "#000000", "#DCDCDC", "#DCDCDC", 0, 0, 0, 0, null);
//	sIFR.replaceElement("h3", "tradegothic.swf", "#000000", null, null, null, 0, 0, 0, 0, null);

}

var anim_ref = null;
var timer_ref = null;
var is_anim_over = false;

function setAnimateScrollBar()
{
		setTimeout(function()
		{
			if (is_anim_over != true)
				repeatAnimScrollBar();
			if (anim_ref == null) anim_ref = 1;
		}, 
		5000);
						
		$("#scrollBar").mouseover(function()
		{
			if (anim_ref != null)
				anim_ref.stop();
			is_anim_over = true;
    	});

		$("#scrollBar").mouseout(function()
		{
			if (anim_ref != null)
				repeatAnimScrollBar();
			is_anim_over = false;
    	});		
}

function repeatAnimScrollBar()
{
	var speed_val = 70;
		
	var scroll_top = $("#scrollBar").scrollTop();
	var height_sb = $("#scrollBar ul").height();
	
	time_anim = speed_val * (height_sb - scroll_top);
	
	anim_ref = $("#scrollBar").animate( { scrollTop : height_sb + 'px'}, {
			duration: time_anim,
			easing: 'linear',
			complete: function(){ $("#scrollBar").scrollTop(0); repeatAnimScrollBar() }
	});	
}

function cleanInput(ob){
	return ob.value = '';
}

function counter(obj){
	return obj.value=obj.value.slice(0,400);
}

function goToPerview(){
	return document.getElementById('aEdit').submit();
}

function showActionBar(obj){
	var t = obj.id.split('_');
	var name = 'action_' + t[1];
	return $("table." + name).slideToggle('normal');
}

function hideActionBar(obj){
	var t = obj.id.split('_');
	var name = 'action_' + t[1];
	return $("table." + name).slideUp('normal');
}

function showMsgBox(name){	
	$("#contactform_" + name).slideToggle('normal');
}

function chngOfrTp(obj){
	if(obj.value == 1){
		$("tr.oType").hide();
		$("tr.oType2").show();
	}else{
		$("tr.oType").show();
		$("tr.oType2").hide();
	}
}

	function sendMsg(){
		advAJAX.post({
			url: "send_ajax.php",
			parameters: {
				uid: get("fcUid").value,
				url: get("fcUrl").value,
				name: get("fcName").value,
				tel: get("fcPhone").value,
				mail: get("fcMail").value,
				content: get("fcContent").value
			},
			onSuccess: function(obj){
			
				get("contactBox").innerHTML = obj.responseText;
				window.setTimeout(document.location.reload(true),2000);
			},
			onLoading: function(obj){
			
				get("contactBox").innerHTML = '\
				<div class="loadingBox">\
					<p>Ładowanie strony ...<p>\
					<img src="/images/ajax-loader.gif" />\
				</div>';
			},
			onError: function(obj){
				alert("Error: " + obj.status);
			}
		});
	}
	
	function sendMsg2(obj, name){

		advAJAX.post({
			url: "send_ajax.php",
			parameters: {
				uid: obj.form.fcUid.value,
				url: obj.form.fcUrl.value,
				name: obj.form.fcName.value,
				tel: obj.form.fcPhone.value,
				mail: obj.form.fcMail.value,
				content: obj.form.fcContent.value
			},
			onSuccess: function(obj){
			
				get("contactform_" + name).innerHTML = obj.responseText;
				window.setTimeout(document.location.reload(true),2000);
			},
			onLoading: function(obj){
			
				get("contactform_" + name).innerHTML = '\
				<div class="loadingBox">\
					<p>Ładowanie strony ...<p>\
					<img src="/images/ajax-loader.gif" />\
				</div>';
			},
			onError: function(obj){
				alert("Error: " + obj.status);
			}
		});
	}
	
	function sendMsg3(){
		advAJAX.post({
			url: "send_ajax2.php",
			parameters: {
				aid: get("fcAid").value,
				url: get("fcUrl").value,
				rodzaj: get("fcRodzaj").value,
				content: get("fcContent2").value,
				mail: "info@baunet.pl"
			},
			onSuccess: function(obj){
			
				get("reportBox").innerHTML = obj.responseText;
				window.setTimeout(document.location.reload(true),2000);
			},
			onLoading: function(obj){
			
				get("reportBox").innerHTML = '\
				<div class="loadingBox">\
					<p>Ładowanie strony ...<p>\
					<img src="/images/ajax-loader.gif" />\
				</div>';
			},
			onError: function(obj){
				alert("Error: " + obj.status);
			}
		});
	}
	
