// openId base javascript 

var spShow = false;
var IE = document.all?true:false;
var x, y;

var actIcoPartner = "spgbtn1";

var minAge_se = "";
var maxAge_se = "";
var gender_se = "";
isSetGender = false;
isSetAge = false;
isSetNick = false;
isSetCity = false;

var spa = new Array(null,0,1,1,1,1,1,1,1);

function setGenderS(mf) {
	gender_se = mf;
	if(gender_se != 'W') isSetGender = true;
	else isSetGender = false;
}
function setAgeS(minA,maxA) {
	minAge_se = minA ;
	maxAge_se = maxA;
	if((minAge_se != 0) && (maxAge_se != 0)) isSetAge = true;
	else isSetAge = false;
}
function setNickS() {
	isSetNick = true;
}
function setCityS() {
	isSetCity = true;
}

function sendSearchS() {
	nick_se = $("#searchName").val();
	city_se = $("#searchCity").val();
	
	sendSpath = "?action=search_result";
	if(isSetNick == true) sendSpath += "&nick="+nick_se;
	if(isSetGender == true) sendSpath += "&gender="+gender_se;
	if(isSetAge == true) sendSpath += "&age_min="+minAge_se+"&age_max="+maxAge_se;
	if(isSetCity == true) sendSpath += "&city="+city_se;
	
		window.location = sendSpath;
}

function menu(btnId) {
	var widthBtn = new Array(159,153,126,163,165,210);
	if(btnId == 0){
		$("#menuHbtn1").append('<div id="mhBtnAct1" class="menuTest"></div>');
		$("#mhBtnAct1").css( {width:widthBtn[btnId]+"px", background:'url(./images/header/m'+(btnId+1)+'_act.png)'} );
		$("#menuHbtn1,#mhBtnAct1").unbind();
	}
	if(btnId == 1) { 
		$("#menuHbtn2").append('<div id="mhBtnAct1" class="menuTest"></div>');
		$("#mhBtnAct1").css( {width:widthBtn[btnId]+"px", background:'url(./images/header/m'+(btnId+1)+'_act.png)'} );
		$("#menuHbtn2,#mhBtnAct1").unbind();
	}
	if(btnId == 2) {
		$("#menuHbtn3").append('<div id="mhBtnAct1" class="menuTest"></div>');
		$("#mhBtnAct1").css( {width:widthBtn[btnId]+"px", background:'url(./images/header/m'+(btnId+1)+'_act.png)'} );
		$("#menuHbtn3,#mhBtnAct1").unbind();
	}
	if(btnId == 3) {
		$("#menuHbtn4").append('<div id="mhBtnAct1" class="menuTest"></div>');
		$("#mhBtnAct1").css( {width:widthBtn[btnId]+"px", background:'url(./images/header/m'+(btnId+1)+'_act.png)'} );
		$("#menuHbtn4,#mhBtnAct1").unbind();
	}
	if(btnId == 4) {
		$("#menuHbtn5").append('<div id="mhBtnAct1" class="menuTest"></div>');
		$("#mhBtnAct1").css( {width:widthBtn[btnId]+"px", background:'url(./images/header/m'+(btnId+1)+'_act.png)'} );
		$("#menuHbtn5,#mhBtnAct1").unbind();
	}
}


function loadSite(loadSiteId) {
	if(loadSiteId == 0) {window.location = "index.php"; }
	if(loadSiteId == 1) {window.location = "?action=articles"; }
	if(loadSiteId == 2) {window.location = "?action=rating"; }
	if(loadSiteId == 3) {window.location = "?action=search"; }
	if(loadSiteId == 4) {window.location = "?action=register"; }
}

function menuHover() {
	$("#menuHbtn1,#menuHbtn2,#menuHbtn3,#menuHbtn4,#menuHbtn5").mouseover(function() {
			$(this).animate({ opacity: 0 }, 300 );
	});
	$("#menuHbtn1,#menuHbtn2,#menuHbtn3,#menuHbtn4,#menuHbtn5").mouseout(function() {
			$(this).animate({ opacity: 1 }, 300 );
	});
}

function showHideSp(isVisible) {
	if(isVisible == false) {
		spShow = true;
			$("#menuHbtn6").css( {height:"61px", background:"url(./images/header/m6_b.gif)"} );
			$("#partnerS").hide();
	}
		
		$("#menuHbtn6").click(function() { 
			if(spShow == false) {
				$("#partnerS").slideUp().queue(function() { 
				$("#menuHbtn6").css( {height:"61px", background:"url(./images/header/m6_b.gif)"} ); 
				$(this).dequeue(); });
				$("#menuHomeSepCenter").animate( {width:"0px",height:"0px"},0);
				spShow = true; return; 
			}
			if(spShow == true) { 
				$("#menuHbtn6").css( {height:"66px", background:"url(./images/header/m6.gif)"} );
				$("#partnerS").slideDown();  spShow = false;
				$("#menuHomeSepCenter").animate( {height:"2px"},0).queue(function() {
						$(this).animate( {width:"990px"},900); $(this).dequeue(); }); 
			}
		});
}

function icoPartnerHover() {
	$(".minLogoPrt").mouseover(function() { if(this.id != actIcoPartner) $(this).css("border","3px solid #d9d5ce"); });
	$(".minLogoPrt").mouseout(function() { if(this.id != actIcoPartner) $(this).css("border","3px solid #FFF"); });
}


function getXY(e) {
	if (window.IE) { 
		x = event.clientX + document.body.scrollLeft
		y = event.clientY + document.body.scrollTop
	} else {
		x = e.clientX
		y = e.clientY
	}
}

function menuPartner() {
		$("#icoPrt1,#icoPrt2,#icoPrt3").mouseover(function() {
					$(this).css("display","none");
					$("#"+this.id+"H").show();
			 });
		$("#icoPrt1H,#icoPrt2H,#icoPrt3H").mouseout(function() {
					$(this).css("display","none");
					$("#icoPrt1").css("display","block");
					$("#icoPrt2").css("display","block");
					$("#icoPrt3").css("display","block");
			 });
}

/* galeria , serwisy partnerskie */
function servGallery() {
		$("#spgbtn1,#spgbtn2,#spgbtn3,#spgbtn4,#spgbtn5,#spgbtn6,#spgbtn7,#spgbtn8").click(function() {
			if(actIcoPartner != this.id) {
				$("#"+actIcoPartner).css("border","3px solid #FFF");
				$(this).css("border","3px solid #d9d5ce");
				re = /[0-9]$/; tfc = this.id; tfrm = re.exec(tfc);
				$(".ptText").load("./include/ps"+tfrm+".htm");
				$("#partnerLogoView").empty();
				$("#ptLogo").empty();
				$("#partnerLogoView").append('<img src="./images/header/imagesLogo/maxLogo'+tfrm+'.gif" alt="" />');
				$("#ptLogo").append('<img src="./images/header/imagesLogo/textLogo'+tfrm+'.gif" alt="" />');
				actIcoPartner = this.id;
					if(spa[tfrm] == 1) {
						$("#icoPrt1").empty().append('<img src="./images/header/icoPrt1_nieact.gif" alt="zaloguj sie" />');
						$("#icoPrt2").empty().append('<img src="./images/header/icoPrt2_nieact.gif" alt="moje publikacje" />');
						$("#icoPrt3").empty().append('<img src="./images/header/icoPrt3_nieact.gif" alt="aktywne usługi" />');
						$("#icoPrt1,#icoPrt2,#icoPrt3").unbind();
						$("#icoPrt1H,#icoPrt2H,#icoPrt3H").unbind();
					}
					else {
						$("#icoPrt1").empty().append('<img src="./images/header/icoPrt1.gif" alt="zaloguj sie" />');
						$("#icoPrt2").empty().append('<img src="./images/header/icoPrt2.gif" alt="moje publikacje" />');
						$("#icoPrt3").empty().append('<img src="./images/header/icoPrt3.gif" alt="aktywne usługi" />');
						$("#icoPrt1,#icoPrt2,#icoPrt3").mouseover(function() {
							$(this).css("display","none");
							$("#"+this.id+"H").show();
						});
						$("#icoPrt1H,#icoPrt2H,#icoPrt3H").mouseout(function() {
							$(this).css("display","none");
							$("#icoPrt1").css("display","block");
							$("#icoPrt2").css("display","block");
							$("#icoPrt3").css("display","block");
						});
					}
			}
		});
		$("#"+actIcoPartner).toggleClass("ramkaH2");
	}

function inputDesc() {
		$("#searchName").val(" imie / nazwisko /login");
		$("#searchCity").val(" miasto");
		
		var re=/^\s/;
		
		$("#searchName,#searchCity").click(function() { 
			if(re.exec($(this).val()))
			$(this).css( {color:"#000",paddingLeft:"8px",width:$(this).width()-5+"px"} ).val("").focus();
		});
}

function showGrafTip() { 
	$("#gA1,#gA2,#gA3,#gA4,#gA5,#gA6").mouseover(function() {
			if(this.id == "gA1") $("div.grafToolTip").text("zaloguj sie za friko");
			if(this.id == "gA2") $("div.grafToolTip").text("uzupelnij swoj profil");
			if(this.id == "gA3") $("div.grafToolTip").text("wyszukaj znajomych");
			if(this.id == "gA4") $("div.grafToolTip").text("dodawaj i przegladaj zdjecia oraz wiadomosci ");
			if(this.id == "gA5") $("div.grafToolTip").text("zalogoj sie na serwisy partnerskie");
			if(this.id == "gA6") $("div.grafToolTip").text("100000000000000 $");
			$("div.grafToolTip").css( {top:"700px",left:(y)+"px",visibility:"visible",display:"block"} );
			
	});
	$("#gA1,#gA2,#gA3,#gA4,#gA5,#gA6").mouseout(function() {
			$("div.grafToolTip").css( {visibility:"hidden",display:"none"} );
	});
}

function searchM() {
		$("#searchM").css("background","url(./images/home/search_bg.gif)");
		//$("#searchM").css("background","#f7f5f0");
}


$(document).ready(function(){
	mainBox_width = $(window).width();
	menu_left = ((mainBox_width-990)/2)+775;
	$("#menuHbtn6").css("left",menu_left+"px");
	menuHover();
	icoPartnerHover();
	menuPartner();
	servGallery();
	inputDesc();
	document.onmousemove = getXY;
	$("#newLoginNext").click(function() { checkForm(1); });
	$("#newLoginRegister").click(function() { checkForm(2); });
	$("#menuHbtn6b").append('<div id="menuHbtn6" class="menuTest"></div>');
});