<link rel="stylesheet" type="text/css" href="<?=base_url()?>js/shadowbox-3.0.3/shadowbox.css">
<script type="text/javascript" src="<?=base_url()?>js/shadowbox-3.0.3/shadowbox.js"></script>
<script type="text/javascript">
Shadowbox.init();
</script>

<script type="text/javascript" src="<?=base_url()?>js/jquery.form.js"></script>

				<!--<link rel="stylesheet" href="<?php echo base_url() ?>css/jquery.fileupload-ui.css">
				-->

				<!--<p style="margin-bottom: 10px;"><?php foreach($parents as $node){
					echo '<img src="'.base_url().'images/icon_arrow.png" align="baseline" style=" position:relative; top:4px;" /><a href="'.base_url().'admin/wyswietl/'.$node->id.'">'.$node->nodeData['name'].'</a>';
				 } 
				echo '<img src="'.base_url().'images/icon_arrow.png" align="baseline" style=" position:relative; top:4px;" /><a href="'.base_url().'admin/module/'.$this->uri->segment(3).'">'.$module->modules_name; ?></a> </p>
				
				
				<div id="navigationContener">
				<p ><img src="<?php echo base_url(); ?>images/navigation_head_icon.png" align="absmiddle" style="" /> <?php foreach($parents as $node){
					echo '<img src="'.base_url().'images/next_navigation.png" align="absmiddle" style="" /><a href="'.base_url().'admin/wyswietl/'.$node->id.'">'.$node->nodeData['name'].'</a>';
				 } 
				 echo '<img src="'.base_url().'images/next_navigation.png" align="absmiddle" style="" /><a href="'.base_url().'admin/module/'.$this->uri->segment(3).'">'.$module->modules_name.'</a>';
				?> </p>
                </div>-->
				
				<div class="breadcrumb ui-corner-tl ui-corner-tr">
                <div style="float:left; position:relative;"><img class="breadcrumbIcon" align="absmiddle"  src="<?php echo base_url();?>images/homePage.png" /><a href="<?php echo base_url(); ?>">Strona WWW</a><img src="<?php echo base_url(); ?>images/breadcrumbSeparator.png" align="absmiddle" style="" /></div>
                <?php
				$counter = count($parents);
				$count = 1;
				$lastNode = null;
				 foreach($parents as $node){
					 
					echo '<div class="contenerNodeBreadcrumb"><img src='.base_url().'images/newspaper.png align="absmiddle" class="breadcrumbIcon"><a href="'.base_url().'admin/wyswietl/'.$node->id.'">'.truncate($node->nodeData['name']).'</a>';
				//	if($counter==$count) echo '<img style="position:absolute; left:40%; top:32px;" src='.base_url().'images/pointer_breadcrumb.png /> ';
				
					echo '</div><img src="'.base_url().'images/breadcrumbSeparator.png"  align="absmiddle"  class="separatorBreadcrumb" />'; 
				 $count++;
				 $lastNode = $node; 
				 } 
				 echo '<div class="contenerNodeBreadcrumb"><img src="'.base_url().'images/brick_mini.png" align="absmiddle" class="breadcrumbIcon" /><a  href="'.base_url().'admin/module/'.$this->uri->segment(3).'">'.truncate($module->modules_name).'</a> <img class="pointerBreadcrumb" src='.base_url().'images/pointer_breadcrumb.png /></div>';
				?>
                <a href="<?php echo base_url()?>admin/wyswietl/<?php echo $lastNode->id ?>"><img src="<?=base_url(); ?>images/back_cms_main.png" border="0" style="float:right;"></a>
                </div>		
				<br/>
				<script type="text/javascript">
				function successFunc(data)  { 
					//alert(data);
					$('#ajax-loader').html("");
					var base_url = "<?php echo base_url(); ?>";
					var i = Math.floor(Math.random()*100000);
			        var modId = "<?php echo $this->uri->segment(3); ?>";


		            if(!$.browser.msie) $("#sortablePhotos").html('Proszę czekać...').load(base_url+"admin/module/"+modId+" li.photosLi");
		            else window.location.href="<?=base_url()?>admin/module/<?=$this->uri->segment(3)?>";
		            Shadowbox.init();
				}
				$(document).ready(function(){
					$('form.upload input[name=plik]').change(function(){
	                    
						$('form.upload input[name=header]').val($("#galeria_form input[name=header]").val());
						$('form.upload input[name=description]').val($("#galeria_form input[name=description]").val());
						$('form.upload input[name=x]').val($("#galeria_form input[name=x]").val());
						$('form.upload input[name=y]').val($("#galeria_form input[name=y]").val());
						$('form.upload input[name=foto_x]').val($("#galeria_form input[name=foto_x]").val());
						$('form.upload input[name=foto_y]').val($("#galeria_form input[name=foto_y]").val());
						$('form.upload input[name=module_id]').val($("#galeria_form input[name=module_id]").val());
						
						var options = { 
						        target:        '',   // target element(s) to be updated with server response 
						        dataType:	'html', 
						        success:	successFunc  // post-submit callback 
						 		//,
						 		//url: '<?=base_url()?>index.php/strona/tmp_logo'
						    }; 
						$("form.upload").ajaxSubmit(options);
	                    					                
						$('#ajax-loader').html("<img src='<?=base_url()?>images/ajax-loader.gif' />");
					});
				});
				</script>
				<form id="galeria_form" action="<?php echo base_url(); ?>admin/addphoto" method="post" enctype="multipart/form-data">
				<table border="0" cellpadding="0" cellspacing="0"  id="id-form">
					<tr><th>Nowe zdjęcie: </th></tr>
					<tr>
						<th valign="top" style="font-weight:normal;" >Nagłówek:</th>
						<td><input type="text" class="inp-form" name="header" /></td>
						<td class="error-td">&nbsp;</td>
					</tr>
					<tr>
					<th valign="top" style="font-weight:normal;">Opis:</th>
						<td><input type="text" class="inp-form" name="description" /></td>
						<td>&nbsp;</td>
						
					</tr>
					
					<tr><th>Docelowy rozmiar zdjęcia:</th></tr>
					<tr style="display: none;">
					<th valign="top" style="font-weight:normal;">Wysokość (px):</th>
						
						<td><input type="text" class="inp-form" name="foto_y" value="600"/></td>
						<td class="error-td">&nbsp;</td>
					</tr>
					<tr>
					<th valign="top" style="font-weight:normal;">Szerokość (px):</th>
						
						<td><input type="text" class="inp-form" name="foto_x" value="800"/></td>
						<td class="error-td">&nbsp;</td>
					</tr>
					
					<tr><th>Rozmiar miniaturki:</th></tr>
					<tr style="display: none;">
					<th valign="top" style="font-weight:normal;">Wysokość (px):</th>
						
						<td><input type="text" class="inp-form" name="y" value="<?php echo $rozmiar->y; ?>"/></td>
						<td class="error-td">&nbsp;</td>
					</tr>
					<tr>
					<th valign="top" style="font-weight:normal;">Szerokość (px):</th>
						
						<td><input type="text" class="inp-form" name="x" value="<?php echo $rozmiar->x; ?>"/></td>
						<td class="error-td">&nbsp;</td>
					</tr>
					
					<tr>
					<th>Wybierz zdjęcia:</th>
						<!--<td><input type="FILE" class="file_1" name="plik" /></td>
						<td>&nbsp;</td>-->
											
						
					</tr>
					
					<tr><td >
					<input type="hidden" name="module_id" value="<?php echo $this->uri->segment(3); ?>" />
								
					
                 
					</td >
                    <td style="padding-left:0px;">  
                     <!--<a style="margin-left:10px;" class="submit button buttonBlack "><img src="<?php echo base_url(); ?>images/buttons/disc.png" />Zapisz</a>
                     --></td>
                     <td></td>
                    </tr>
				</table>
					
				</form>
				
				<form class="upload" action="<?php echo base_url(); ?>admin/addphoto/1" method="POST" enctype="multipart/form-data">
					<input type="file" name="plik" ><!-- multiple-->
					
                    <input type="hidden" name="header" value=""/>
                    <input type="hidden" name="description" value=""/>
                    <input type="hidden" name="x" value=""/>
                    <input type="hidden" name="y" value=""/>
                    <input type="hidden" name="foto_x" value=""/>
                    <input type="hidden" name="foto_y" value=""/>
                    <input type="hidden" name="module_id" value=""/>
                    
					<!--<button>Upload</button>
					<div class=""><img src="<?php echo base_url(); ?>images/image_add.png" align="absmiddle" /> Dodaj zdjęcia</div>
				-->
				</form>
				
				<br/><br/>
				<div id="ajax-loader"></div>
				<table class="upload_files"></table>
				<table class="download_files"></table>
				
				<br/><br/>
				
								
				
				<!--
				<form action="<?php echo base_url(); ?>admin/addphoto" method="post" enctype="multipart/form-data">
					<p>Nowe zdjęcie:</p>
					<input type="hidden" name="x" value="<?php echo $rozmiar->x; ?>" />
					<input type="hidden" name="y" value="<?php echo $rozmiar->y; ?>" />
					<input type="hidden" name="module_id" value="<?php echo $this->uri->segment(3); ?>" />
					<p>Nagłówek</p>
					<p><input type="text" name="header" /></p>
					<p>Opis</p>
					<p><input type="text" name="description" /></p>
					<p>Plik</p>
					<p><input type="FILE" name="plik" /></p>
							
					<p><input type="submit" value="Zapisz" /></p>
				</form><br/>
				-->
				
				
				
				<script type="text/javascript">
				$(document).ready(function(){

					$("form#galeria_form").submit(function(){
						return false;
					});


					
					$("#edytujFoto").dialog({ 
						autoOpen: false,
						//modal: true,
						width: 600,
						//position: [500,100],
						close: function(event, ui) {
							$(".ui-overlay").attr("style", "display:none;");
						},
						buttons:{
							"Anuluj": function(){
								$(this).dialog("close");
								$(".ui-overlay").attr("style","display:none;");
							},
							"Zapisz": function(){
								$(this).find("form input[type=submit]").click();
							}
						}
					});

					$("button.edytujfoto").live('click', function(){
						//alert($(this).attr("id"));
						$("div#edytujFoto form input[name=foto_id]").attr("value", $(this).attr("id"));
						//alert($(this).attr("id"));
						$.getJSON("<?php echo base_url(); ?>admin/getfotodata/"
								+$(this).attr('id'),
							function(data){
								$("div#edytujFoto form input[name=header]").attr("value", data.header);
								$("div#edytujFoto form input[name=desc]").attr("value", data.desc);
																

								$(".ui-overlay").attr("style", "display:block;");
								$("#edytujFoto").dialog("open");
							}
						);
					});
				});
				</script>
								
				
				<script type="text/javascript" src="<?php echo base_url(); ?>js/submitDelete.js"></script>
				
				<div id="edytujFoto" title="Edytuj opis zdjęcia" >
					<h2><strong>Edytuj opis zdjęcia</strong></h2>
					<form action="<?php echo base_url(); ?>admin/edytujfoto" method="post">
						<table border="0" cellpadding="0" cellspacing="0"  id="id-form">
						<tr>
							<th valign="top">Nagłówek:</th>
							<td><table><tr id="input-header">
								<td><input type="text" class="inp-form" name="header" /></td>
								<td class="">
								
								</td>
							</tr></table></td>
						</tr>
						<tr>
							<th valign="top">Opis:</th>
							<td><table><tr id="input-desc">
								<td><input type="text" class="inp-form" name="desc" /></td>
								<td class="">
								
								</td>
							</tr></table></td>
						</tr>
						
						</table>
						<input type="hidden" name="foto_id" value="" />
						<input type="hidden" name="module_id" value="<?= $this->uri->segment(3) ?>" />
						<input style="display: none;" type="submit" value="Edytuj" />
					</form>
				</div>
				
				<ul id="sortablePhotos">
				<?php if($photos && $photos->num_rows()>0) { ?>
			
					<?php foreach ($photos->result() as $photo) { ?>
						<li class="photosLi ui-state-default" id="photo_<?php echo $photo->ID_photos; ?>">
							<?php if(file_exists('foto/'.$photo->photos_name)) { ?>
							<a href="<?php echo base_url().'foto/'.$photo->photos_name; ?>" rel="shadowbox">
								
								<div style="background: url('<?php echo base_url(); ?>foto/thumb_<?php echo $photo->photos_name; ?>') no-repeat scroll 50% 50% transparent;">
								</div>
							</a>
							<?php } else { ?>
							<a href="<?php echo reduce_double_slashes(prep_url($adres).'/foto/'.$photo->photos_name); ?>" rel="shadowbox">
								
								<div style="background: url('<?php echo reduce_double_slashes(prep_url($adres)."/foto/thumb_".$photo->photos_name); ?>') no-repeat scroll 50% 50% transparent;">
								</div>
							</a>
							<?php } ?>
							<p class="photoHeader"><?php echo $photo->photos_header; ?></p>
							<p class="photoHeader"><?php echo $photo->photos_description; ?></p>
							<button title="Edytuj zdjęcie"  class="edytujfoto button buttonLightGrey tooltip" id="<?php echo $photo->ID_photos; ?>" ><img style="margin-right:0px;" src="<?php echo base_url(); ?>images/pencil.png" /></button>
							<form  class="usunfoto" action="<?php echo base_url(); ?>admin/removephoto" method="post">
								<input type="hidden" name="id" value="<?php echo $photo->ID_photos; ?>" />
								<input type="hidden" name="name" value="<?php echo $photo->photos_name; ?>" />
								<input type="hidden" name="module_id" value="<?php echo $photo->photos_module_id; ?>" />
                             
								<button title="Usuń zdjęcie" onclick ="this.submit" class="button buttonLightGrey tooltip"  value="" type="submit"><img style="margin-right:0px;" src="<?php echo base_url(); ?>images/bin.png" /></button>
							</form>
						</li>
					<?php } ?>
				
				
				
				
				<?php } ?>
				</ul>
				<div class="clear"></div>
			
				<!-- 		
				<script src="<?php echo base_url()?>js/jquery.fileupload.js"></script>
				<script src="<?php echo base_url()?>js/jquery.fileupload-ui.js"></script>
				<script>
				$(function () {
					var uploadCounter = 0,
			        onCompleteAll = function () {
						var base_url = "<?php echo base_url(); ?>";
				        var modId = "<?php echo $this->uri->segment(3); ?>";
				        //window.location.reload();
			            $("#sortablePhotos").html('Proszę czekać...').load(base_url+"admin/module/"+modId+" li.photosLi");
			            //$("#sortableFiles").sortable("refresh");			            
			        };
			        var uploadSequence = [];
			        uploadSequence.start = function (index) {
			            var next = this[index];
			            if (next) {
			                next();
			                this[index] = null;
			            }
			        };	        
								
				    $('.upload').fileUploadUI({
				        uploadTable: $('.upload_files'),
				        downloadTable: $('.download_files'),
				        buildUploadRow: function (files, index) {
				            var file = files[index];
				            return $(
				                '<tr>' +
				                '<td>' + file.name + '<\/td>' +
				                '<td class="file_upload_progress"><div><\/div><\/td>' +
				                '<td class="file_upload_cancel">' +
				                '<div class="ui-state-default ui-corner-all ui-state-hover" title="Anuluj">' +
				                '<span class="ui-icon ui-icon-cancel">Anuluj<\/span>' +
				                '<\/div>' +
				                '<\/td>' +
				                '<\/tr>'
				            );
				        					    				            
				        },
				        buildDownloadRow: function (file) {
					        //var base_url = "<?php echo base_url(); ?>";
					        //var modId = "<?php echo $this->uri->segment(3); ?>";
					        
					        //load(base_url+"admin/module/"+modId+" div#dodane_pliki_content");
				        	return $(   '<tr><td>' + file.name + '<\/td><td>&nbsp;-&nbsp;</td><td>'+file.message+'</td><\/tr>'   );
				            //<td>'+file.type+'<\/td><td>'+file.size+'<\/td>
				        },
				        onComplete: function (event, files, index, xhr, handler) {
				        	uploadSequence.start(index + 1);

					        uploadCounter = uploadCounter + 1;
				            if (uploadCounter === files.length) {
				                uploadCounter = 0;
				                //$("div#dodane_pliki").html('asd');
				                
				                onCompleteAll();
				            }
				        },
				        onAbort: function (event, files, index, xhr, handler) {
				            handler.removeNode(handler.uploadRow);
				            uploadCounter = uploadCounter + 1;
				            if (uploadCounter === files.length) {
				                uploadCounter = 0;
				                onCompleteAll();
				            }
				            
				            uploadSequence[index] = null;
				            uploadSequence.start(index + 1);
								            
				        },
				        beforeSend: function (event, files, index, xhr, handler, callBack) {
				        	
				            //handler.uploadRow.find('.file_upload_start').click(function () {
				                handler.formData = {
				                    description: handler.uploadRow.find('.file_upload_desc input').val(),
				                    header: $("#galeria_form input[name=header]").val(),
				                    description: $("#galeria_form input[name=description]").val(),
				                    x: $("#galeria_form input[name=x]").val(),
				                    y: $("#galeria_form input[name=y]").val(),
				                    foto_x: $("#galeria_form input[name=foto_x]").val(),
				                    foto_y: $("#galeria_form input[name=foto_y]").val(),
				                    module_id: $("#galeria_form input[name=module_id]").val()
				                };
				                //callBack();
				            //});
			                uploadSequence.push(callBack);
				            if (index === 0) {
				                uploadSequence.splice(0, uploadSequence.length - 1);
				            }
				            if (index + 1 === files.length) {
				                uploadSequence.start(0);
				            }  
				            //callback();  
				        }
				    				        
								        
								        
				    });
				});
				</script>
				-->
				