/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



$(document).ready(function(){

        if (!$(".dla_prasy").length > 0) {
            $('.menu-main_page a').attr('href','#');
            $('.menu-o_firmie a').attr('href','#');
            $('.menu-certyfikaty a').attr('href','#');
            $('.menu-kontakt a').attr('href','#');
            $("#content div").slideDown("normal");
        }

        $('#img-kartka_swiateczna a').fancybox().trigger('click');

        $('#footer-other a').click(function(){
            window.open(this.href);
            return false;
        });

        $('.boxer-wiecej a').live('click', function(){
            window.open(this.href);
            return false;
        });

        generateSprites(".xxx", "current-", false, 150, "fade");
        generateSprites("#menu ul", "current-", false, 250, "slide");
        generateSprites("#footer-other ul", "current-", false, 250, "fade");
        generateSprites("#grand_menu ul", "current-", false, 250, "fade");

        $('#boxer-iner')
            .before('<div id="boxer-nav">')
            .cycle({
                fx:     'fade',
                speed:  'slow',
                timeout: 15000,
                next:   '#next2',
                prev:   '#prev2',
                pager:  '#boxer-nav'
            });
            
       // Kliki "menu kategorii"
        $('.grand-kosiegowosc a').click(function() {$('#boxer-iner').cycle(0);return false;});
        $('.grand-firma a').click(function() {$('#boxer-iner').cycle(1);return false;});
        $('.grand-dzialalnosc a').click(function() {$('#boxer-iner').cycle(2);return false;});
        $('.grand-przesylki a').click(function() {$('#boxer-iner').cycle(3);return false;});
        $('.grand-nauka a').toggle(function() {$('#boxer-iner').cycle(4);return false;},function() {$('#boxer-iner').cycle(5);return false;});

        $('#wyroznienia div').cycle({fx: 'fade', timeout: 7005, next: '#wyroznienia div'});

        if ( $('.dla_prasy').text().length == 0 ) {
            $('.menu-main_page a').live('click', function() {wczytajRamke('main_page');$('#wyroznienia div').cycle({fx: 'fade', timeout: 7005, next: '#wyroznienia div'});});
            $('.menu-o_firmie a').live('click', function() {wczytajRamke('o_firmie');});
            $('.menu-certyfikaty a').live('click', function() { $("a.zoom").fancybox(); wczytajRamke('certyfikaty');$("a.zoom").fancybox();} );
            $('.menu-kontakt a').live('click', function() {wczytajRamke('kontakt');});
        }
        $("#page").show();
});


function wczytajRamke(wartosc) {

    if (wartosc == 'skp' || wartosc == 'sam' || wartosc == 'stemp' || wartosc == 'pd' || wartosc == 'au' || wartosc == 'pity' ) {
        $('#menu ul').attr('class', 'current-menu-main_page');
    } else {
        var flMovie = getFlashMovieObject('spinerMain');
        
        flMovie.Rewind();//.Rewind();
        $('#menu ul').attr('class', 'current-menu-'+ wartosc);
    }
    loadBox(wartosc);
}

function loadBox(war) {
//    alert(war);
    var lang;
    lang = $("#language").text();
//    alert(lang);
    $.ajax({
        url: "loadPage.php?page="+ war +"&lang="+ lang,
        cache: false,
        async: false,
        success: function(msg){
            $("#content").html(msg);
            $("#content div").slideDown("normal");
            $("#content div").attr("style","display:block;");
            if (war == 'main_page') {
                $('.menu-o_firmie a').attr('href','#');
            }
        }
    });
}

function getFlashMovieObject(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet")==-1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    } else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementById(movieName);
    }
}

function generateSprites(parent, selectedPrefix, setActive, hoverSpeed, style) {
	var parentClass = $(parent).attr("class");

	$(parent).children("li").each(function() {
		var myClass = ($(this).attr("class"))
		var current = parent.substring(1) + " current-" + ($(this).attr("class"));

		attachNavEvents(parent, myClass, setActive, hoverSpeed, style);

        if (parentClass != current) {
			$(this).children("a").css({backgroundImage:"none"});
		}

	});
}


function attachNavEvents(parent, myClass, setActive, hoverSpeed, style) {
	$(parent + " ." + myClass).mouseover(function() {
		$(this).append('<div class="nav-' + myClass + '"></div>');
		if (style == "slide") {
			$("div.nav-" + myClass).css({display:"none"}).slideDown(hoverSpeed);
		} else {
			$("div.nav-" + myClass).css({display:"none"}).fadeIn(hoverSpeed);
		}
	}).mouseout(function() {
		if (style == "slide") {
			$("div.nav-" + myClass).slideUp(hoverSpeed, function() {
				$(this).remove();
			});
		} else {
			$("div.nav-" + myClass).fadeOut(hoverSpeed, function() {
				$(this).remove();
			});
		}
	});

	if (setActive) {
		$(parent + " ." + myClass).mousedown(function() {
			$("div.nav-" + myClass).attr("class", "nav-" + myClass + "-click");
		}).mouseup(function() {
			$("div.nav-" + myClass + "-click").attr("class", "nav-" + myClass);
		});
	}
}
/**
 * jQuery-Plugin "preloadCssImages"
 * by Scott Jehl, scott@filamentgroup.com
 * http://www.filamentgroup.com
 * reference article: http://www.filamentgroup.com/lab/update_automatically_preload_images_from_css_with_jquery/
 * demo page: http://www.filamentgroup.com/examples/preloadImages/index_v2.php
 *
 * Copyright (c) 2008 Filament Group, Inc
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 *
 * Version: 5.0, 10.31.2008
 * Changelog:
 * 	02.20.2008 initial Version 1.0
 *    06.04.2008 Version 2.0 : removed need for any passed arguments. Images load from any and all directories.
 *    06.21.2008 Version 3.0 : Added options for loading status. Fixed IE abs image path bug (thanks Sam Pohlenz).
 *    07.24.2008 Version 4.0 : Added support for @imported CSS (credit: http://marcarea.com/). Fixed support in Opera as well.
 *    10.31.2008 Version: 5.0 : Many feature and performance enhancements from trixta
 * --------------------------------------------------------------------
 */

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)


