var content=[];
var TotalDiv=0;
var PrevPos=0;
var pageChk = "";
var topx;
$(document).ready(function(){
						   	 pageChk = String(window.location);
							var ip = pageChk.indexOf('portfolio');
							
							if(ip!=-1)
							{
							 createPopup();
							 resizing();
							 $(window).resize(resizing);
							}
							$(".MainPopup_container").hide(1);
						     function LoadProductData(linked)
										{
											var AjaxLink=linked;
											$(".hiddenData").load(AjaxLink,productLoadComplete)
																								
										}
										function productLoadComplete()
										{
										
											$('.MainPopup_container .MainDiv_container .title').html($('.hiddenData .title').html());
											$('.MainPopup_container .MainDiv_container .Product_image').html($('.hiddenData .Product_image').html());
											$('.MainPopup_container .MainDiv_container .Product_text').html($('.hiddenData .Product_text').html());
											
										}
						   var htmlC="";
						    $('.MainPopup_container').hide();
							var W = $(window).width();
							var H = $(window).height();
							
							$('.MainPopup_container').css('width',W);
						//	$('.MainPopup_container').css('height',H);
							
							
							//$('.MainPopup_container').css('opacity',0.5);
							
						   $('.MainPopup_container .MainDiv_container .close').bind('click',function(){
																									 
																									 $('.MainPopup_container').hide();
																									 
																									 });
						    $('.MainPopup_container .MainDiv_container .Larr').bind('click',function(){
																									 var htmlc=$('.MainPopup_container .Page_status').html();
																									 var CurrentPos ="";
																									 var EndPos = htmlc.indexOf('o');
																									 
																									 for(var i=0; i < (EndPos-1) ; i++)
																									 {
																										 CurrentPos = CurrentPos + htmlc.charAt(i);
																									 }
																									 
																									PrevPos= CurrentPos-1;
																									if(PrevPos >0)
																									{
																								$('.MainPopup_container .Page_status').html(PrevPos +" of "+ (TotalDiv+1));
																									linked = hlink + "/portfolio-images/popupajax/page_"+(PrevPos-1)+".html"
																									LoadProductData(linked);
																									}
																									 
																									 });
							 $('.MainPopup_container .MainDiv_container .Rarr').bind('click',function(){
																									 var htmlc=$('.MainPopup_container .Page_status').html();
																									 var CurrentPos ="";
																									 var EndPos = htmlc.indexOf('o');
																									 
																									 for(var i=0; i < (EndPos-1) ; i++)
																									 {
																										 CurrentPos = CurrentPos + htmlc.charAt(i);
																										 
																									 }
																									nextPos= parseInt(CurrentPos) + 1;
																									if(nextPos <= TotalDiv+1)
																									{
																								$('.MainPopup_container .Page_status').html(nextPos +" of "+ (TotalDiv+1));
																									linked = hlink + "/portfolio-images/popupajax/page_"+(nextPos-1)+".html"
																									LoadProductData(linked);
																									}
																									 
																									 });
						  
				
				
				
				
				
				
				
				
				
				
				$('.thumbnailContainer li').each(function(n){
																	    
																		var obj = new Object();
																		obj.src = $(this).find('img').attr('src');
																	    obj.description = $(this).find('span').html();
																		obj.id = "th_"+n;
																		obj.href = $(this).find('a').attr('href');
																	    content.push(obj);
																		htmlC = htmlC+getHTML(obj)+"\n\n";
																		TotalDiv=n;
																		});
						   
						   
						   $('.MainPopup_container .Page_status').html((1) + " of " + (TotalDiv+1));
																										linked = hlink + "/portfolio-images/popupajax/page_"+0+".html";
																										LoadProductData(linked);
																										$('.MainPopup_container').show();
						   
						   
						   $('.thumbnailContainer').html(htmlC);
						   $('.thumbnailContainer .thumb').each(function(m){
																		 		
																		 		var DivId =$(this).attr('id');
																				DivId=parseInt(DivId.split('_')[1]);
																				
																		 $(this).attr('href',hlink + "/portfolio-images/popupajax/page_"+DivId+".html");
																		$(this).find('.sh').css('opacity',0.8); 
																		 $(this).find('.description').css('left',185);
																		 
																		 $(this).bind('click',function(e){
																										e.preventDefault();
																									resizing();
  
																								$('.MainPopup_container .Page_status').html((DivId+1) + " of " + (TotalDiv+1));
																										linked = $(this).attr('href');
																										LoadProductData(linked);
																										$('.MainPopup_container').show();
																											
																					
																								       });
																		 
																		 
																		 $(this).bind('mouseover',function(){
																										   
 																	     $(this).find('.description').animate({left:0},{queue:false});
																		 $(this).find('img').animate({opacity:0.3},{queue:false})							     
																											 });
																		 
																		 $(this).bind('mouseleave',function(){
																										   
 																	     $(this).find('.description').animate({left:185},{queue:false});
																		$(this).find('img').animate({opacity:1},{queue:false})									     
																											 });
																		 
								
								});
						   
						   
						 
						   
						
						   
						   });



function getHTML(obj)
{
  var htmlc = '<div id="'+obj.id+'" class="thumb">';
  htmlc = htmlc+'<div class="innerContainer">';
  htmlc = htmlc+'<img src="'+obj.src+'"/>';
  htmlc = htmlc+'<div class="description">';
  htmlc = htmlc+'<div class="sh"></div>';
  htmlc = htmlc+'<div class="txt">'+obj.description+'</div>';
  htmlc = htmlc+'</div>';
  htmlc = htmlc+'</div>';
  htmlc = htmlc+'</div>';	
  
  return htmlc;
	
}



function createPopup()
{
    var htmlc = '<div class="MainPopup_container">';
	htmlc = htmlc+'<div id="shadow" style="position:fixed; background:#000000; left:0px; top:0px;"></div>'
	htmlc = htmlc+'<div class="MainDiv_container" style="position:absolute;">';
	htmlc = htmlc+'<span class="title"></span>';
	htmlc = htmlc+'<div class="Larr"></div>';
	htmlc = htmlc+'<div class="Page_status">0 of 22</div>';
	htmlc = htmlc+'<div class="Rarr"></div>';
	htmlc = htmlc+'<div class="close"></div>';
	htmlc = htmlc+'<div class="Product_image"></div>';
	htmlc = htmlc+'<div class="Product_text"></div>';
    htmlc = htmlc+'</div>';
    htmlc = htmlc+'<div class="hiddenData"></div>';
    htmlc = htmlc+'</div>';
	
	$('body').append(htmlc)
}

function resizing()
{
  var W  =$(window).width();
  var H = $(window).height();
  
  topx = $(window).scrollTop();
   
  tgttop = topx+5;
  
 
    $('.MainPopup_container').css('top',0);
  $('.MainDiv_container').animate({top:tgttop},600);
  
  $('.MainDiv_container').css('left',(W - $('.MainDiv_container').width())/2);
  $('#shadow').css('opacity',0.8);
  $('#shadow').css('width',W);
  $('#shadow').css('height',H);
  
}
