

/*!
 * (v) Compact labels plugin
 * Takes one option: labelOpacity [default: true] set to false to disable label opacity change on empty input focus
 */
(function($){$.fn.compactize=function(options){var defaults={labelOpacity:true};options=$.extend(defaults,options);return this.each(function(){var label=$(this),input=$('#'+label.attr('for'));input.focus(function(){if(options.labelOpacity){if(input.val()===''){label.css('opacity','0.5');}}else{label.hide();}});if(options.labelOpacity){input.keydown(function(){label.hide();label.css('opacity',1);});} input.blur(function(){if(input.val()===''){label.show();} if(options.labelOpacity){label.css('opacity',1);}});window.setTimeout(function(){label.toggle(input.val()==='');},50);});};})(jQuery);



/*!
 * (v) hrefID jQuery extention
 * returns a valid #hash string from link href attribute in Internet Explorer
 */
(function($){$.fn.extend({hrefId:function(){return $(this).attr('href').substr($(this).attr('href').indexOf('#'));}});})(jQuery);

/*!
 * Scripts
 *
 */
 

jQuery(function($) {
 
	var Engine = {
		utils : {
			links : function(){
				$('a[rel*=external]').click(function(e){
					e.preventDefault();
					window.open($(this).attr('href'));						  
				});
			},
			mails : function(){
				$('a[href^=mailto:]').each(function(){
					var mail = $(this).attr('href').replace('mailto:','');
					var replaced = mail.replace('/at/','@');
					$(this).attr('href','mailto:'+replaced);
					if($(this).text() == mail) {
						$(this).text(replaced);
					}
				});
			}
		}
	};

	Engine.utils.links();
	Engine.utils.mails();
	
});


/*
 * jQuery hashchange event - v1.3 - 7/21/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);


/* FORMULARZ KONTAKTOWY */


function ContactFormAppendActions(mode) {

    jQuery("#FormularzKontaktowy .cancel, #FormularzKontaktowy .closeButton").show().click(function() { 
    
        jQuery("#FormularzKontaktowy").fadeOut(function() {
            jQuery("#FormularzKontaktowy").remove();
        });
    }).css({"display":"block"});
    
    if (jQuery("#sym-it-cont").length>0 || mode=="it") {
        jQuery(".closeButton").attr("src", "/images/symetria-it/closeButton.gif");
        jQuery("#FormularzKontaktowy form").append('<input type="hidden" name="symetria_it" value="1" />');
    }    
    if (mode=="creative") {
        jQuery(".closeButton").attr("src", "/images/creative/closeButton.gif");
        jQuery("#FormularzKontaktowy form").append('<input type="hidden" name="symetria_cr" value="1" />');    
    }

    jQuery("#FormularzKontaktowy form").submit(function() {
        
        jQuery(this).find(".error").removeClass("error");
        
        jQuery("#FormularzKontaktowy .komunikat").remove();
        
        var errors = [];
        var wiadomosc = jQuery(this).find("textarea[name='wiadomosc']");
        if (wiadomosc.val() == "") {
            errors[errors.length] = {name:'wiadomosc', fieldset:'wiadomosc'};
        }
        
        var odkogo = jQuery(this).find("input[name='odkogo']");
        if (odkogo.val() == "") {
            errors[errors.length] = {name:'odkogo', fieldset:'odkogo'};
        }
    
        var email = jQuery(this).find("input[name='email']");
        if (!(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.(?:[A-Z]{2,2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)$/i.test(jQuery.trim(email.val())))) {
            errors[errors.length] = {name:'email', fieldset:'email'};
        }

        var zgoda = jQuery(this).find("input[name='zgoda']");
        if (!jQuery("#zgoda").attr("checked")) {
            errors[errors.length] = {name:'zgoda', fieldset:'zgoda_field'};
        }
        
    
        if (errors.length>0) {
        
            jQuery(errors).each(function() {
                jQuery("#FormularzKontaktowy #"+this.fieldset).addClass("error");
            });
            return false;
        }
        
        if (jQuery(this).find("input[name='ajax']")) {
            var action = jQuery(this).attr("action");
            jQuery.post(action, jQuery(this).serialize(), function(data){
                var odp = "" + data;
                if (odp.match("@@@ok@@@")) {
                    jQuery("#FormularzKontaktowy form").remove();
                    jQuery("#FormularzKontaktowy").append("<div><b>Dziękujemy za kontakt</b><br /><br />Twoja wiadomość własnie do nas dotarła. Nasz konsultant odpowie na wskazany przez Ciebie adres.</div>");
                } else {
                    jQuery("#FormularzKontaktowy").prepend("<div class='error komunikat'><b style='font-size:16px; color:red;'>Przepraszamy</b><br /><br />Wystąpił problem komunikacji z serwerem. Prosimy spróbować raz jeszcze lub wysłać wiadomość na adres: <a href='mailto:biuro@symetria.pl'>biuro@symetria.pl</a> <br /><br /><br /></div>");
                }
            });
            return false;
        }
        
    }).append("<input type='hidden' name='ajax' value='1' />");

    var cfx = jQuery(document).width()/2 - jQuery("#FormularzKontaktowy").outerWidth()/2;
    jQuery("#FormularzKontaktowy").css({left:cfx+"px"});
}

function RunContactForm(cb, mode) {

    if (!document.location.href.match('http://www.')) {
        ContactFormURL = ContactFormURL.replace('http://www.', 'http://');
    }


    if (jQuery("#FormularzKontaktowy").length == 0) {
        jQuery.get(ContactFormURL+"&ajax=1", function(data){
            var div = document.createElement('div');
            jQuery(div).html(data);
            if (jQuery("#content").length>0) {
                jQuery("#content").prepend(div);
            }    
            else if (jQuery("#sym-it-cont").length>0) {
                 
                jQuery("#sym-it-cont").prepend(div);
            }
            else if (jQuery("#sym-cr-cont").length>0) {
                 
                jQuery("#sym-cr-cont").prepend(div);
            }
            else {
                return false;
            }     
            ContactFormAppendActions(mode);
            window.scrollTo(0,0);
            if (typeof(cb)=="function") cb();
        });
    }
}

jQuery(document).ready(function() {

    jQuery(".cf-trigger, .cf-it-trigger, .cf-creative-trigger").each(function() {
        
        var content = jQuery(this).html();
        var elem=this;
        var mode = false;
        if (jQuery(this).hasClass("cf-it-trigger")) mode = "it";
        if (jQuery(this).hasClass("cf-creative-trigger")) mode = "creative";
        jQuery(this).click(function() {
            if (jQuery("#FormularzKontaktowy").length > 0) return false;
            jQuery(this).blur();
            jQuery(elem).html(" ... Ładowanie ... ");
            RunContactForm(function() { jQuery(elem).html(content); }, mode);
            return false;
        });
    });
    
    jQuery(".removeMe").remove();
    
    if (document.location.hash == '#kontaktForm') {
        RunContactForm();
    } 
});




function appendJJLightBox(filter, multi) {
    
    if (!filter) filter = "*";
    
    function showInBox(src, title) {
        
        jQuery("#ImgBox").remove();
        
        var mode = "img";
        if (src.match("youtube")) {
            mode = "yt";
            var movieID = src.match(/v=([a-z0-9\-\.\,]*)?/i);
            if (movieID && movieID[1]) {
                movieID = movieID[1];
            }
        }
        
        
        if (!title || title=="") title = "Podgląd";
        
        var html = '<div id="ImgBox" class="new-layer">';
            html +='<h2><img src="/images/closeButton.gif" alt="X" class="closeButton" title="Zamknij" />'+title+' </h2>';
            html +='<div class="indicator"></div>';
            if (mode == "img") {
                html +='<div style="text-align:center;"><img src="/images/preloader_big.gif" alt="" id="ImgBoxPreloader" /></div>';
                html +='<img src="'+src+'" alt="" id="ImgBoxPhoto" />';
            }
            if (mode == "yt") {
                html += '<iframe title="YouTube video player" class="youtube-player" type="text/html" width="480" height="390" src="http://www.youtube.com/embed/'+movieID+'?rel=0" frameborder="0"></iframe>';
            }
            html +='<div class="cancel"><a href="#">Zamknij</a></div> '
            html += '</div>'
            
        jQuery("#content").prepend(html);
        jQuery("#ImgBox .cancel, #ImgBox .closeButton, #ImgBox #ImgBoxPhoto").show().click(function() { 
        
            jQuery("#ImgBox").fadeOut(function() {
                jQuery("#ImgBox").remove();
            });
        }).css({cursor:"pointer"});        
        
        var cfx = jQuery(window).width()/2 - jQuery("#ImgBox").outerWidth()/2;
        var cfy = (jQuery(window).height()/2 - jQuery("#ImgBox").outerHeight()/2) + jQuery(window).scrollTop();
        if (cfy < 0) cfy = 0;
        
        jQuery("#ImgBox").css({left:cfx+"px", top:cfy+"px"});
        
        if (mode=="img") {    
            jQuery("#ImgBox #ImgBoxPhoto").hide().load(function() {
                jQuery("#ImgBox #ImgBoxPreloader").hide();
                jQuery(this).show();
                jQuery("#ImgBox h2").css({width:jQuery(this).outerWidth()+"px", overflow:"auto", height:"auto"});
                
                var cfx = jQuery(window).width()/2 - jQuery("#ImgBox").outerWidth()/2;
                var cfy = (jQuery(window).height()/2 - jQuery("#ImgBox").outerHeight()/2) + jQuery(window).scrollTop();
                if (cfy < 0) cfy = 0;
                if (jQuery(this).outerWidth() >= jQuery(window).width()) cfx = 0;
                if (jQuery(this).outerHeight() >= jQuery(window).height()) cfy = 10;
                
                jQuery("#ImgBox").css({left:cfx+"px"});
                if (cfy!=false) {
                    jQuery("#ImgBox").css({top:cfy+"px"});
                }    
                jQuery(this).hide().fadeIn();
            });
        }
     
        return false;   
    }
    
    
    jQuery("a").filter(filter).each(function() {
        
        var href = jQuery(this).attr("href");
        
        var title = jQuery(this).attr("title"); 
        if (href.match(/\.(jpg|gif|png|bmp)$/i) || href.match("youtube.com")) {
        
            jQuery(this).click(function() {
                showInBox(href, title);
                return false;
            });
        }
    });

}

jQuery(document).ready(function() {
    appendJJLightBox(false, false);
});


jQuery(document).ready(function() {
   

jQuery("img.switch_bw").hover(
  function () {
  	var sr = jQuery(this).attr('src').replace("_bw.png",".png");
  	jQuery(this).attr('src',sr);
  }, 
  function () {
    var sr = jQuery(this).attr('src').replace(".png","_bw.png");
  	jQuery(this).attr('src',sr);
  }
);
});

