var bo_ns_id = 0;



function startIeFix() {
    
    if(isIE()) {
        
        document.write('<div id="bo_ns_id_' + bo_ns_id + '"><!-- ');
    }
}



function endIeFix() {
    
    if(isIE()) {
        
        document.write('</div>');
        
        var theObject = document.getElementById("bo_ns_id_" + bo_ns_id++);
        
        var theCode = theObject.innerHTML;
        
        theCode = theCode.substring(4 ,9+theCode.indexOf("</object>"))
        
        document.write(theCode);
    }
}



function isIE() {
    
    // only for Win IE 6+
    
    // But not in Windows 98, Me, NT 4.0, 2000
    
    var strBrwsr= navigator.userAgent.toLowerCase();
    
    if(strBrwsr.indexOf("msie") > -1 && strBrwsr.indexOf("mac") < 0) {
        
        if(parseInt(strBrwsr.charAt(strBrwsr.indexOf("msie")+5)) < 6) {
            
            return false;
        }
        
        if(strBrwsr.indexOf("win98") > -1 ||
        
        strBrwsr.indexOf("win 9x 4.90") > -1 ||
        
        strBrwsr.indexOf("winnt4.0") > -1 ||
        
        strBrwsr.indexOf("windows nt 5.0") > -1) {
            
            return false;
        }
        
        return true;
    } else {
        
        return false;
    }
}



/* 

<script type="text/javascript">startIeFix();</script>

>> FLASH <<

<!-- --><script type="text/javascript">endIeFix();</script>

*/

Nowe = null;


function Show(id) {
    
    
    winwidth = 400;
    
    winheight = 400;
    
    xpoz = screen.width/2 - winwidth/2;
    
    ypoz = screen.height/2 - winheight/2;
    
    maxy = screen.height;
    maxx = screen.width;
    
    Nowe=null;
    
    Nowe=window.open("foto/pokaz.php?id="+id+"&x="+maxx+"&y="+maxy, "","toolbar=no,menubar=no,location=no,personalbar=no, scrollbars=yes,status=no,directories=no,resizable=yes,height="+winheight+",width="+winwidth+",left="+xpoz+",top="+ypoz);
    
    Nowe.focus();
}

function Init() {
	$('#ButtonsLeftBottom').each(function(){
		var tr_l = parseInt($('#tresc_l').height());
		var tr	= parseInt($('#tresc').height());
		if (tr > tr_l) $(this).css('margin-top', (tr - tr_l) + 'px');
		
	});
	EventsInit2();
	LightboxInit();
	$('#Gwiazdki').each(function(){SetStars();});
}

function SetStars() {
	srednia = Math.floor(parseInt($('#Gwiazdki INPUT[name="suma"]').val()) / parseInt($('#Gwiazdki INPUT[name="iloscGlosow"]').val()));
	for (i = 1; i <= 5; i++) {
		if (i <= srednia) $('#Gwiazdki A[name="star' + i + '"]').css('background-position', 'top');
					  else $('#Gwiazdki A[name="star' + i + '"]').css('background-position', 'bottom');
	}
}

	// ---=========================---
	// ---=== Obsługa LightBoxa ===---
	// ---=========================---

function LightboxInit() {
	function in_array(n, h, s) {
	    var f = false, k, s = !!s;
	    for (k in h) {
	        if ((s && h[k] === n) || (!s && h[k] == n)) {
	            f = true;
	            break;
	        }
	    }
	    return f;
	}
	function UseLightbox(string) {
		string = string.toLowerCase();
		if (string.indexOf('.jpg') > 0) return true;
		if (string.indexOf('.jpeg') > 0) return true;
		if (string.indexOf('.gif') > 0) return true;
		if (string.indexOf('.png') > 0) return true;
		if (string.indexOf('.bmp') > 0) return true;
		if (string.indexOf('.tif') > 0) return true;
		return false;
	}
	$("A[rel='']").each(function(){
		if (UseLightbox($(this).attr('href'))) $(this).attr('rel', 'lightbox[643r1dth3f67id53hr]');
	});
	
	var lightboxTab = Array();
	$("A[rel^='lightbox']").each(function(){
		var v = $(this).attr('rel');
		if (!in_array(v, lightboxTab)) lightboxTab[lightboxTab.length] = v;
	});
	for (i = 0; i < lightboxTab.length; i++) {
		$("A[rel='" + lightboxTab[i] + "']").lightBox();
		$("A[rel='" + lightboxTab[i] + "']").attr("title", "Kliknij z boku zdjęcia aby zobaczyć następne.");		
	}
}

	// ---========================---

function EventsInit2() {
	$('#GlosujButton').click(function(){
		var w = null;
		var ip = $('input[name="ip"]').val();
		$('#SondaDIV').find('input[@type=radio]').each(function(){
			if ($(this).attr('checked') == true) w = $(this).val();
		});
		if (w) {
			$.ajax({
				type: "POST",
				url : "ajax/glosuj.ajax.php",
				data: "ido=" + w + '&ip=' + ip,
				success: function(odp) {
					$('#SondaDIV').html(odp);
				}
			})
		} else alert('Nie zaznaczono żadnej odpowiedzi!');
	});
	
	$('.glosujButton').click(function(){
		var nr = parseInt($(this).attr('name'));
		var w = null;
		var ip = $('input[name="ip"]').val();
		$('.sonda' + nr).find('input[@type=radio]').each(function(){
			if ($(this).attr('checked') == true) w = $(this).val();
		});
		if (w) {
			$.ajax({
				type: "POST",
				url : "ajax/glosuj.ajax.php",
				data: "ido=" + w + '&ip=' + ip,
				success: function(odp) {
					$('.sonda' + nr).html(odp);
				}
			})
		} else alert('Nie zaznaczono żadnej odpowiedzi!');
	});
	
	if (parseInt($('#Gwiazdki INPUT[name="twojGlos"]').val()) == 0) {
		$('#Gwiazdki A').hover(function(){
			id = parseInt($(this).attr('name').substr(4));
			for (i = 1; i <= 5; i++) {
				if (i <= id) $('#Gwiazdki A[name="star' + i + '"]').css('background-position', 'top');
						  else $('#Gwiazdki A[name="star' + i + '"]').css('background-position', 'bottom');
			}
		}, function(){
			SetStars();
		});
		
		$('#Gwiazdki A').click(function(){
			var glos = parseInt($(this).attr('name').substr(4));
			var id   = parseInt($('#Gwiazdki INPUT[name="artykulId"]').val());
			$.ajax({
				type: "POST",
				url : "ajax/oceniaj.ajax.php",
				data: "artId=" + id + '&ocena=' + glos,
				success: function(odp) {
					if (odp != 'error') document.location.href='index.php?pid=4&art=' + odp;
										else alert('Wystąpił błąd!!');
				}
			});
		});
	}
	
	$('.jezykBtn').click(function(){
		if (document.getElementById('flagi').style.display == 'block') {
			document.getElementById('flagi').style.display='none';
			$('#top2').css('background-position', 'top left');
		} else {
			document.getElementById('flagi').style.display='block';
			$('#top2').css('background-position', 'bottom left');
		}
	});
}


if (window.addEventListener) {
	window.addEventListener("load", Init, false);
}else if (window.attachEvent) {
	window.attachEvent("onload", Init);
}