/*
$Id: main.js 694 2008-07-07 21:20:33Z marcin $
*/


var WindowObjectReference = null;
var PreviousUrl = null;


function openWindowUrl(strUrl)
{
	return window.open(strUrl, 'Window',
         "resizable=yes,width=800,height=550,scrollbars=yes,status=no,location=no,toolbar=no,'menubar=no,left=5,top=5");
}

function openUrl(strUrl)
{
	if(WindowObjectReference == null || WindowObjectReference.closed)
	{
		WindowObjectReference = openWindowUrl(strUrl);
	}
	else if(PreviousUrl != strUrl)
	{
		WindowObjectReference = openWindowUrl(strUrl);
	}

	WindowObjectReference.focus();

	PreviousUrl = strUrl;
}


var imgHover = '_hover.png?a=5';
var imgLink = '_link.png?a=5';
var imgActive = '_active.png?a=5';

var imgBaseUrl = baseUrl+'/files/layout/default/';

function bindMenuItem(val, index, isActive, imgBaseUrl)
{
	if(isActive == true)
	{
		$('a', val).html('<img src="'+imgBaseUrl+index+imgActive+'" alt="" />');
	}
	else
	{
		$('a', val).html('<img src="'+imgBaseUrl+index+imgLink+'" alt="" />')
			.data('hover', imgBaseUrl+index+imgHover)
			.data('link', imgBaseUrl+index+imgLink)
			.hover(
		      function () {
		        $('img', this).attr('src', $(this).data('hover'));
		      },
		      function () {
		        $('img', this).attr('src', $(this).data('link'));
		      }
	    	).click(function () {
	    		$(this).unbind('mouseout').unbind('mouseover');
	    		$('img', this).attr('src', $(this).data('hover'));
	    	});
	}
}

$(document).ready(function()
{
	 jQuery.each($('#wrap-items div.menu-item'), function(i, val) {
	 	if(	(i == 0 && menuActive == 'o-firmie') ||
	 		(i == 1 && menuActive == 'oferta') ||
                        (i == 2 && menuActive == 'aktualnosci') ||
	 		(i == 3 && menuActive == 'warunki-wspolpracy') ||
	 		(i == 4 && menuActive == 'kontakt'))
	 	{
			bindMenuItem(val, i+1, true, imgBaseUrl);
	 	}
	 	else
	 	{
	 		bindMenuItem(val, i+1, false, imgBaseUrl);
	 	}
    });


	jQuery.each($('#content-right div.items'), function(i, val) {
		$('a',val).lightBox({fixedNavigation:true});
    });

    /*
    $('#content-right div.item img').fadeTo("slow", 0.9);

    $('#content-right div.item img').hover(
      function () {
        $(this).fadeTo("fast", 1.0);
      },
      function () {
        $(this).fadeTo("fast", 0.9);
      }
    );
    */

    /*Intro*/
     jQuery.each($('#intro-menu div.intro-menu-item'), function(i, val) {
	 	bindMenuItem(val, i+1, false, imgBaseUrl+'intro/');
    });


    /*Preload images*/
    $.preload( [ '1'+imgHover, '2'+imgHover, '3'+imgHover, '4'+imgHover, '5'+imgHover,], {
	 		base:imgBaseUrl
	});
	$.preload( [ '1'+imgHover, '2'+imgHover, '3'+imgHover, '4'+imgHover, '5'+imgHover,], {
	 		base:imgBaseUrl+'intro/'
	});
	

});

