﻿jQuery.prototype.toArray = function() {        var rval = [];        this.each(function(){rval.push($(this).val())});        return rval;}function _doDownload(sender){    var doct_id = sender.getAttribute('doct_id');    if (doct_id != undefined)    location.href = location.pathname + 'admin/' + '?doct_id=' + doct_id;    return false;}jQuery.prototype.corner = function(top,bottom,t_style,b_style) { if($(this).length>0 ){  if(parseInt(jQuery.browser.version)<=6 && $.browser.msie){ // hack to ie6 rouding problem	var itemHeight=$(this).height()+parseInt($(this).css('padding-bottom'))+parseInt($(this).css('padding-top'));	if(itemHeight%2){		var _bottom='-2px';	}else{		var _bottom='-1px';	}  }else{		var _bottom='-1px';  }  $(this).css({position:'relative',zoom:1});  if(top=="top"){  
	$(this).append("<img src='"+t_style[0]+"' class='tl' />");
	$('.tl',this).css({
		position:"absolute",
		left:'-1px',
		top:'-1px',		zIndex:10
	});
	$(this).append("<img src='"+t_style[1]+"' class='tr' />");
	$('.tr',this).css({
		position:"absolute",
		right:'-1px',
		top:'-1px',
		zIndex:10
	});
  }
  if(bottom=="bottom"){
	$(this).append("<img src='"+b_style[0]+"' class='bl' />");
	$('.bl',this).css({
		position:"absolute",
		left:'-1px',
		bottom:_bottom,		zIndex:10
	});	$(this).append("<img src='"+b_style[1]+"' class='br' />");
	$('.br',this).css({
		position:"absolute",
		right:'-1px',
		bottom:_bottom,
		zIndex:10
	});
  } }
}

jQuery.prototype.wallpapperGallery = function(width,height,fit,icons,title,wallpaper,lightbox) {
	if($(this).length>0 && $("li",this).length>0){
	if($("li.active",this).length==0){
		$("li:first",this).addClass("active");
	}
	var id=$(this).attr("class");
	$(this).wrap("<div class='main_image_"+id+"'></div>");
	$(".main_image_"+id).css({width:width+'px',height:height+'px',overflow:'hidden',position:'relative',margin:0,padding:0,border:'1px solid #BABABA',background:"#efefef"});
	if(wallpaper){
		$(".main_image_"+id).after("<div class='download'><span>"+wallpaper[0]+"</span></div>");
		if(wallpaper[1]) $(".download").append("<a href='#'>"+wallpaper[1]+"</a>");
		if(wallpaper[2]) $(".download").append("<a href='#'>"+wallpaper[2]+"</a>");
		$(".download a").click(function(){
			$(this).blur();
			if($(this).attr("id")=="wpBtn1"){
				var wpType="normal";
			}else{
				var wpType="panorama";
			}
			var imageActiveSrc=$(".main_image_"+id+" img.active").attr("src");
			var imagePathPos=imageActiveSrc.lastIndexOf("/")+1;
			var imagePath=imageActiveSrc.substring(0,imagePathPos)+wpType+"/";
			var imageName=imageActiveSrc.substring(imagePathPos);
			var imageWpSrc=imagePath+imageName;
			//alert(imageWpSrc);
			location.href="/admin/includes/file_download.php?path="+imageWpSrc;
			return false;
		});
		$(".download").css("width",width-4+"px");
	}
	
	var iconWidth=Math.ceil(width*0.15);
	var iconHeight=Math.ceil(height*0.15);
	var thisLi=$("li.active",this);
	var that=$(this);
	var opacity=0.4;
	
	var iconBottom=15;
	$(this).css({position:'absolute',zIndex:"5",margin:0,padding:"10px 5px",bottom:iconBottom+"px",left:"5px",overflow:"hidden",height:iconHeight+"px",width:"2000px"});
	
	
	if($("li",this).length>1){
		$("li img",this).css({width:iconWidth+"px",border:0});
		$("li",this).css({float:"left",overflow:"hidden",height:iconHeight+"px",cursor:"pointer"});
		$("li",this).css("border",icons[0]);
		$("li",this).css("margin",icons[1]);
		$("li",this).css("background",icons[2]);
		$("li",this).not('.active').children('img').fadeTo('fast',opacity);

		$("li",this).hover(
			function() { $("img",this).fadeTo('fast',1); },
			function() { $(this).not('.active').children('img').fadeTo('fast',opacity); } // don't fade out if the parent is active
		)
		$("li",this).click(function(){
			displayMainPict($("img",this),fit,title);
			thisLi.removeClass("active");
			$("img",thisLi).fadeTo('fast',opacity)
			$(this).addClass("active");
			thisLi=$(this);
			if(lightbox){
				index=$("li",that).index(this);
			}
		});

		var mainOffset=$("li:last",this).offset();
		var mainOffset2=$("li:first",this).offset();
		var iconContainerWidth=mainOffset2.left+(iconWidth+14)*$("li",this).length;		
		var main_imageOffset=$(".main_image_"+id).offset();	
		if(iconContainerWidth-main_imageOffset.left-width>5){
			var scrollWidth=width-10;
			$(".main_image_"+id).append("<div class='srollLine'></div>");
			$(".srollLine").css({position:'absolute',zIndex:"6",margin:"0 5px",padding:0,bottom:iconBottom-8+"px",height:"1px",width:scrollWidth+"px",background:"#ececec",lineHeight:'0px',fontSize:"0px"});
			var srollLineOffset=$(".srollLine").offset();

			$(".main_image_"+id).append("<img src='/gfx/slider_dark.png' class='scroll' />");
			$(".scroll").css({position:'absolute',zIndex:"7",bottom:iconBottom-14+"px",left:'5px',cursor:'pointer'});
			$(".scroll").draggable({ axis: 'x',containment: '.srollLine',opacity: 0.7,drag: function(event, ui) {
				var scrollOffset=$(".scroll").offset();
				var scrollPos=(scrollOffset.left-srollLineOffset.left)/(scrollWidth-14);
				var offsetLeft=-Math.ceil((iconContainerWidth-srollLineOffset.left+20-width)*scrollPos);
				that.css("left",offsetLeft+"px");
			}
			});
		}
	}
	$(".main_image_"+id).css("text-align","center");//musi być tutaj inaczej się sypie przewijanie w ie.	$(".main_image_"+id).wrap("<div class='"+$(this).attr("class")+"' id='"+$(this).attr("id")+"_div'></div>");
	if(lightbox){
		var index="";
		$(".main_image_"+id).append("<div class='lightboxContainer'></div>");
		$(".main_image_"+id+" .lightboxContainer").css("display","none");
		$(".main_image_"+id+" .lightboxContainer").append("<span id='lightbox-img-label'>"+lightbox[0]+"</span><span id='lightbox-of-label'>"+lightbox[1]+"</span>")
		jQuery.each($("li img",this), function(i) {
			$(".main_image_"+id+" .lightboxContainer").append("<a href='"+$(this).attr("src").replace(/\/th\//, "/")+"' class='lightbox"+id+"' title='"+$(this).attr("title")+"'>#</a>");
			if($(this).parent().attr("class")=="active") index=i;

		});
		$(".lightbox"+id).lightBox();
	}
	displayMainPict($(".active img",this),fit,title,true);
	
	}
	


	function displayMainPict(that,fit,title){

		var src=$(that).attr('src').replace(/\/th\//, "/");
		var titleTxt=$(that).attr('alt');
		$(".main_image_"+id+" img.active").remove();
		$(".main_image_"+id).append("<img src='"+src+"' class='active'/>");
		if(fit=='both'){
			$(".main_image_"+id+" img.active").css("width",width+"px");
			$(".main_image_"+id+" img.active").css("height",height+"px");
		}else if(fit=='vertical'){
			$(".main_image_"+id+" img.active").css("width",width+"px");
		}else if(fit=='horizontal'){
			$(".main_image_"+id+" img.active").css("height",height+"px");
		}
		if(title){
			$(".main_image_"+id+" p").remove();
			$(".main_image_"+id).append("<p>"+titleTxt+"</p>");
			$(".main_image_"+id+" p").css({position:'absolute',zIndex:"10",margin:'0',padding:'2px'});
			$(".main_image_"+id+" p").css(title[0],'0px');
			$(".main_image_"+id+" p").css(title[1],'0px');
			$(".main_image_"+id+" p").css("background-color",title[2]);
			$(".main_image_"+id+" p").css("color",title[3]);
			$(".main_image_"+id+" p").fadeTo(0,0.75);
		}
		if(lightbox){	
			$(".main_image_"+id+" img.active").css("cursor","pointer");
			$(".main_image_"+id+" img.active").click(function(){	
				$(".lightbox"+id+":eq("+index+")").trigger('click');
			});
		}
	
	}
	
}

$(document).ready(function(){
	$('.box1').corner("top","bottom",['/gfx/corners/c_big_left.gif','/gfx/corners/c_big_right.gif'],['/gfx/corners/c_bottom_left.gif','/gfx/corners/c_bottom_right.gif']);
	$('.box1 .content').corner("","bottom",'',['/gfx/corners/c_bottom_b_left.gif','/gfx/corners/c_bottom_b_right.gif']);
	$('.box2 .content').corner("top","bottom",['/gfx/corners/c_small_left.gif','/gfx/corners/c_small_right.gif'],['/gfx/corners/c_bottom_left.gif','/gfx/corners/c_bottom_right.gif']);
	$('h1.main').corner("top","bottom",['/gfx/corners/c_small2_left.gif','/gfx/corners/c_small2_right.gif'],['/gfx/corners/c_bottom_left.gif','/gfx/corners/c_bottom_right.gif']);
	
	$('.actMenu').corner("top","",['/gfx/corners/c_big_left.gif','/gfx/corners/c_big_right.gif'],"");
	$('.actMenu .content').corner("","bottom",'',['/gfx/corners/c_bottom_b_left.gif','/gfx/corners/c_bottom_b_right.gif']);
	
	$('.infoBox .content').corner("top","bottom",['/gfx/corners/c_small_left.gif','/gfx/corners/c_small_right.gif'],['/gfx/corners/c_bottom_left.gif','/gfx/corners/c_bottom_right.gif']);

	var t_tapeta=$("#t_tapeta").html();	var t_standard=$("#t_standard").html();	var t_panorama=$("#t_panorama").html();	var t_zdj=$("#t_zdj").html();	var t_z=$("#t_z").html();	var t_show=$("#t_show").html();	var t_hide=$("#t_hide").html();
	$('ul.galeria').wallpapperGallery(518,305,"vertical",["3px double #111","0 5px","#333"],["top","left","#D4D4D4","#000"],[t_tapeta,t_standard,t_panorama]);
	$('ul.aktGal').wallpapperGallery(513,380,"horizontal",["3px double #111","0 5px","#333"],["top","left","#D4D4D4","#000"],"",[t_zdj,t_z]);
	$('ul.isoGal').wallpapperGallery(513,390,"horizontal",["3px double #111","0 5px","#333"],["top","left","#D4D4D4","#000"],"",[t_zdj,t_z]);
	$('ul.rysGal').wallpapperGallery(513,370,"both",["3px double #111","0 5px","#333"],["top","left","#D4D4D4","#000"],"",[t_zdj,t_z]);
	$(".oferta li").hover(
		function() { $("h2",this).not('.active').addClass("preactive"); },
		function() { $("h2",this).not('.active').removeClass("preactive"); } // don't fade out if the parent is active
	)
	$(".oferta li").click(function(){
		$(".oferta li").removeClass();
		$(this).addClass("active");
	});
	$("#newsPreview .inactive").click(function(){
		$("#newsPreview .active").addClass("inactive");
		$("#newsPreview .inactive").removeClass("active");
		$(this).addClass("active");
		var that=$("#newsPreview");
		var prevIndex=$("div",that).index(this)/2;
		$("#slider div.active").removeClass("active");
		$("#slider div.slider:eq("+prevIndex+")").addClass("active");
		$(this).blur();	
		return false
	});
	$("#col2 .oferta li:first").addClass("active");
	$("#slider .slider:first").addClass("active");
	$("#newsPreview .inactive:first").addClass("active");
	$("#newsPreview .inactive a").click(function(){
		$(this).blur();	
		$(this).parent().trigger("click");
		return false
	});
	$("#newsPreview .active a").click(function(){
		$(this).blur();
		return false
	});
	$(".show").click(function(){
		if($(this).prev().is(':visible')){
			$(this).prev().hide("normal");
			$(this).html(t_show);
		}else{
			$(this).prev().show("normal");
			$(this).html(t_hide);		}
		});
	$(".actMenu .header_big").click(function(){
		var that=$(this).parent();
		if($(".links",that).is(':visible')){
			$(".links",that).hide("normal");
			$(".show",that).html(t_show);
		}else{
			$(".links",that).show("normal");
			$(".show",that).html(t_hide);
		}
	});
	
	$(".actMenu .anch").click(function(){
		var that=$(this).parent();
		if($("ul",that).is(':visible')){
			$("ul",that).hide();
		}else{
			$("ul",that).show();
		}
		return false;
	});

})
