this.vtip = function() {    
    this.xOffset = 0; // x distance from mouse
    this.yOffset = 32; // y distance from mouse       
    
    $(".vtip").unbind().hover(    
        function(e) {
            this.t = this.title;
            this.title = ''; 
//            this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
			var o=$(this).offset();
            this.top = (o.top + yOffset);
			this.left = (o.left + xOffset);
			this.top1 = this.top+10;
            
            $('body').append( '<p id="vtip"><img id="vtipArrow" />' + this.t + '</p>' );
                        
            $('p#vtip #vtipArrow').attr("src", '/images/2010/layout/pakiety/vtip_arrow.png');
            $('p#vtip')
			.css("top", this.top+"px")
			.css("left", this.left+"px")

			.fadeIn("slow");
        },
        function() {
            this.title = this.t;
            $("p#vtip").fadeOut("slow").remove();
        }
    );/*.mousemove(
        function(e) {
            this.top = (e.pageY + yOffset);
            this.left = (e.pageX + xOffset);
                         
            $("p#vtip").css("top", this.top+"px").css("left", this.left+"px");
        }
    );*/
    
};

this.vtip2 = function() {    
    this.xOffset = -20; // x distance from mouse
    this.yOffset = 32; // y distance from mouse       
    
    $(".vtip2").unbind().hover(    
        function(e) {
            this.t = this.title;
            this.title = ''; 
//            this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
			var o=$(this).offset();
            this.top = (o.top + yOffset);
			this.left = (o.left + xOffset);
			this.top1 = this.top+10;
            
            $('body').append( '<p id="vtip"><img id="vtipArrow" />' + this.t + '</p>' );
                        
            $('p#vtip #vtipArrow').attr("src", '/images/2010/layout/pakiety/vtip_arrow.png');
            $('p#vtip')
			.css("top", this.top+"px")
			.css("left", this.left+"px")

			.fadeIn("slow");
        },
        function() {
            this.title = this.t;
            $("p#vtip").fadeOut("slow").remove();
        }
    );/*.mousemove(
        function(e) {
            this.top = (e.pageY + yOffset);
            this.left = (e.pageX + xOffset);
                         
            $("p#vtip").css("top", this.top+"px").css("left", this.left+"px");
        }
    );*/
    
};
// funkcja zmiany linkow

function linkChe(idLink,idLink2)
{
	var adres = window.location.href;
	var w = new Array();
	w = adres.split("_");
	 
	if ( w[1] == "abo" ) {
          if ( idLink2 == undefined ) { link = "/_abo_" + idLink + ".html" }
          else { link = "/_abo_" + idLink + "_" + idLink2 +".html" }
          }
	else if ( w[1] == "pro" ) { 
          if ( idLink2 == undefined ) { link = "/_pro_" + idLink + "-pro.html" }
          else { link = "/_pro_" + idLink + "-pro_" + idLink2 +".html" }
        }
	else { 
         if ( idLink2 == undefined ) { link = "/cyfra_" + idLink + ".html" }
         else { link = "/cyfra_" + idLink + "_" + idLink2 + ".html" }
        }

//	return window.document.write(link);
return window.location.href=link;
}


// popup

function pop_html (plik,szer,wys,scroll) {
 ustawienia = 'width=' +  szer  + ',height=' +  wys  + ',scrollbars=' + scroll ;
 var okono = window.open ( plik,'xx',ustawienia) ;
// okono.resizeTo( (szer + 10 ) , (wys + 30 ) );
 okono.focus() ;
}


//
// POP- UP  **************************
//

noweokno=null;



function winopen(plik, w, h, scroll) {

if(window.screen) {
  aw=screen.availwidth;
  ah=screen.availheight;
}else{
  aw=640;
  ah=450;
}if(noweokno==null || noweokno.closed){
 ustawienia=
 "left="+(aw-w)/2+","
 +"top="+(ah-h)/2+","
 +"screenX="+(aw-w)/2+","
 +"screenY="+(ah-h)/2+","
 +"width="+w+","
 +"height="+h+","
 +"toolbar=no,"
 +"location=no,"
 +"directories=no,"
 +"status=np,"
 +"menubar=no,"
 +"scrollbars="+scroll+","
 +"resizable=no"
 noweokno=window.open(plik,'nowe',ustawienia);
 noweokno.focus();
}else{
 noweokno.close();
  ustawienia=
 "left="+(aw-w)/2+","
 +"top="+(ah-h)/2+","
 +"screenX="+(aw-w)/2+","
 +"screenY="+(ah-h)/2+","
 +"width="+w+","
 +"height="+h+","
 +"toolbar=no,"
 +"location=no,"
 +"directories=no,"
 +"status=np,"
 +"menubar=no,"
 +"scrollbars="+scroll+","
 +"resizable=no"
 noweokno=window.open(plik,'nowe',ustawienia);
 noweokno.focus();
}
}


// **************************************


function printpopup(plik,szer,wys) {
window.open(plik,'printt','toolbar=yes,menubar=no,location=no,personalbar=no,scrollbars=yes,directories=no,status=no,resizable=no,width=' + szer + ',height=' + wys);
}


// **************************************

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// **************************************
// FUNKCJA CENTRUJACA DIVY NA STRONIE

function centerDiv(nameDiv){
	if (window.innerWidth&&window.innerHeight){
		var w=window.innerWidth;
		var h=window.innerHeight;
	} else {
		var w=document.body.clientWidth;
		var h=document.body.clientHeight;
	}
	var o=document.getElementById(nameDiv);
	var cx=parseInt(o.style.width);
	o.style.left=(w/2-cx/2)+"px";
}

// **************************************


// tlo lewa

function checkH(){
	var _div=document.getElementById('left-bg');
	
	if (_div)
	{
		var x,y;
		 if (self.innerHeight) // all except Explorer
		 {
			x = self.innerWidth;
			y = self.innerHeight;
		 }
		 else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
		 {
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		 }
		 else if (document.body) // other Explorers
		 {
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		 }
		 
		_div.style.height=(y-500)+"px";
		_div.style.minHeight=(y-490)+"px";
	}
}


function trim(lancuch)
{
	while (lancuch.charAt(0) == " ") 
		lancuch = lancuch.substring(1,lancuch.length);
	while (lancuch.charAt(lancuch.length-1) == " ") 
		lancuch = lancuch.substring(0,lancuch.length-2);
	return lancuch;	
};

function IsNum( txt )
{
	first=true;
	dot=false;
	for( i=0; i < txt.length; i++)
	{
		switch (txt.charAt(i))
		{
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
			case '0':
				first=false;
				continue;
			case ',':
			case '.':
				if (dot) return false;
				dot=true;
				first=false;
				continue;
			case '-':
			case '+':
				if (!first) return false;
				first=false;
				continue;
			default:
				return false;
		}
	}
	return true;
}

function IsEmpty( txt )
{
	for( i=0; i < txt.length; i++)
	{
		switch (txt.charAt(i))
		{
			case '\n':
			case '\r':
			case ' ':
				continue;
			default:
				return false;
		}
	}
	return true;
}

function CheckEMail(email)
{
	if (trim(email) == '')
		return false;
	if (email.indexOf('@') == -1)
		return false;
	if (email.length < 4)
		return false;
	if (email.indexOf('@') != email.lastIndexOf('@'))
		return false;
	if (email.indexOf(' ') != -1)
		return false;
	return true;
}

function mail(co) 
{ 
	Wzor=/^[0-9a-zA-Z-.]+\@[0-9a-zA-Z-]+\.[0-9a-zA-Z-.]+$/; 
	OK=(Wzor.test(document.form.elements[co].value)==true && document.form.elements[co].value.length!=0); 
	if(OK==false)
	{
		alert("podaj poprawny adres");
		document.form.elements[co].focus();
		return false;
	}
	else
	{
	return true;
	}
}

function isValidEmail(email, required) {
	if (required==undefined) { 
		required=true;
	}
	if (email==null) {
		if (required) {
			return false;
		}
		return true;
	}
	if (email.length==0) {  
		if (required) {
			return false;
		}
		return true;
	}
	if (! allValidChars(email)) {
		return false;
	}
	if (email.indexOf("@") < 1) {
		return false;
	} else if (email.lastIndexOf(".") <= email.indexOf("@")) {
		return false;
	} else if (email.indexOf("@") == email.length) {
		return false;
	}
	
	return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-";
  for (var i=0; i < email.length; i++) {
	var letter = email.charAt(i).toLowerCase();
	if (validchars.indexOf(letter) != -1)
	  continue;
	parsed = false;
	break;
  }
  return parsed;
}

function emailAct(form){
	email=form.F_MAIL.value;
	if (!isValidEmail(email)){
		alert("Niepoprawny adres email! Podaj go jeszcze raz!");
		form.F_MAIL.select();
		return false;
	} else {
		return true;
	}
}

function close_send_form()
{
	$("#send_frame").fadeOut('normal', function (){
		$('#send_frame').remove();
	});
}

function send_link_email()
{
	var _email=$("#F_MAIL").val();
	var _link=$("#F_LINK").val();
	var _kto=$("#F_KTO").val();
	var _msg=$("#F_COMMENT").val();
	
	if (isValidEmail(_email)==false)
	{
		alert("Podaj poprawny adres e-mail!");
		return false;
	}
	else
	{
		$.ajax({
			  url: "/includes/2010/send_link_email.php",
			  type: "POST",
			  data: ({url : _link, email : _email, od : _kto, msg : _msg}),
			  success: function(msg){
						if (msg=="1")
						{
							close_send_form();
							alert('Wiadomość została wysłana!');
						}
						else
						{
							alert('Wiadomość nie została wysłana! Spróbuj za chwilę ponownie.');
						}
					  }
		   }
		);
	}
}

$(function(){
	$('#btn_print').click(function(){
		window.print();
		return false;
	});

	$('#btn_send').click(function(){
		if ($("#send_frame").length==0)
		{
			$('body').append('<div id="send_frame"></div>');
			$("#send_frame").css('display','none');

			var t=$(window).scrollTop();
			var w=$('body').innerWidth();
			var h=$(window).height();
			$("#send_frame").load('/includes/2010/send_link.php', { 'link' : document.location.href}, function (){
				var pos_x=Math.round((w-$("#send_frame").width())/2);
				var pos_y=t+Math.round( (h-$("#send_frame").height())/2 );
				$("#send_frame").css({ "top" : pos_y+"px", "left" : pos_x+"px" });
				$("#send_frame").fadeIn('normal');
			});
		}
		else
		{
			var t=$(window).scrollTop();
			var w=$('body').innerWidth();
			var h=$(window).height();
			$("#send_frame").load('/includes/2010/send_link.php', { 'link' : document.location.href}, function (){
				var pos_x=Math.round((w-$("#send_frame").width())/2);
				var pos_y=t+Math.round( (h-$("#send_frame").height())/2 );
				$("#send_frame").css({ "top" : pos_y+"px", "left" : pos_x+"px" });
				$("#send_frame").fadeIn('normal');
			});
		}
		return false;
	});
	
	
	// ------------------- linki - dlugie nazwy VOD
	$("li.title a").bind("mouseover", function()
	{
		$(this).parent().css({"height": "auto", "background-color": "#eaeaec"});
	});
	$("li.title a").bind("mouseout", function()
	{
		$(this).parent().css({"height": "2.1em", "background-color":"transparent"});
	});
	// ------------------- /linki - dlugie nazwy VOD
	
	
	// ------------------- MAGAZYN+
/*	$('#slideout_magplus').tabSlideOut({
            tabHandle: '.handle-mp',
            pathToTabImage: '/images/2010/layout/magazyn/magazyn.gif',
            imageHeight: '118px',
            imageWidth: '24px',
            tabLocation: 'right',
            speed: 250,
            action: 'hover',
            btmPos: '10px',
			topPos: 'none',
            rightPos: '24px',
            fixedPosition: true
        });*/
	// ------------------- /MAGAZYN+
	vtip();
	vtip2();
});
