
function str_replace(search, replace, subject) {
   return subject.split(search).join(replace);
}

$(function(){

	var setting='';
	var screenH;
	var screenW;
	$('#fd').hide();
	$('#lod').hide();
	$('#rb').hide();
	
	var hh  = $('#bg img').size();
	var nim = 220;
	
	
		//animate home page text
	
$('#tar').click(function(){

		$('#htar').addClass('htar');
		$('#hbar').removeClass('hbar');
		var posth = Number($('#postcont1').css('height').replace(/[^-\d\.]/g, ''));
		var to = Number($('#postcont1').css('top').replace(/[^-\d\.]/g, ''));
		var dif12 = posth + to;
		
		if(dif12 > 400){
		$('#postcont1').animate({
		
		
			'top':-nim,
			
		
		},200,function(){
		
			$('#htar').removeClass('htar');
		
		});
		
		  nim += 220;
		};
		
		return false;
	
	});
	
	
	var mov = 0;
	$('#bar').click(function(){
		nim = 220;
		$('#hbar').addClass('hbar');
		$('#htar').removeClass('htar');
		var top = Number($('#postcont1').css('top').replace(/[^-\d\.]/g, ''));
		mov = top + 220;
		if(top != 0){
			$('#postcont1').animate({
			
				'top':mov,
				
			},200,function(){
			
				$('#hbar').removeClass('hbar');
			});
		
			mov +=220;
		}
		
		return false;
		
	});
	
	/*
	$('#bg a').click(function(){
		
		return false;
	
	});
	*/
	
	
$('#postcont img').load(function(){
			var imgh = Number($(this).css('height').replace(/[^-\d\.]/g, ''))/2;			
			var imgw = Number($(this).css('width').replace(/[^-\d\.]/g, ''))/2;
			$(this).css('position','absolute').css('left','50%').css('top','50%').css('margin-left',-imgw).css('margin-top',-imgh);
			//alert(imgw);
		});
		
	$('#bg a').click(function(){
		
		
		var imgsrc = $(this).attr('href');
		var imgtitle = $(this).attr('title');	
      var big = $(this).attr('big');	
		$('#postcont').hide();
		$('#fdd').show();
		$('#fd').show();		
		$('#fdd').addClass('fdd');
		$('#fd').attr('src',imgsrc);
		$('#fd').attr('title',imgtitle);
		$('#fdd > a').attr('href', big);
		$('#fd').load(function(){
			var imgh = Number($(this).css('height').replace(/[^-\d\.]/g, ''))/2;			
			var imgw = Number($(this).css('width').replace(/[^-\d\.]/g, ''))/2;
			$(this).css('position','absolute').css('left','50%').css('top','50%').css('margin-left',-imgw).css('margin-top',-imgh);
			//alert(imgw);
		});
		return false;
	
	});
	
	
		
		
		
	
		
		
		
		
		
		
		
	
		
		
		
		
		
	

	
	
	

	
	
		
	
	
	$('#c').click(function(){
		$('#all').show();
		$('#bgi').remove();
		$('#cl').hide();
		$('#lod').hide();
		$('#dd').remove();
		$('#dd').removeClass('dd');
		return false;
	
	});
	
	
var cc = 0;

var divw = 150;

	
	
	cc = $("#bg img").size();
	
	
	
	$("#bg").css('width',divw*cc);
	
	//var ww = $("#bg").css('width');
	
	
	
	
	
	
	var bgw = Number($('#bg').css('width').replace(/[^-\d\.]/g, ''));
	
	var check = Number($('#check').css('width').replace(/[^-\d\.]/g, ''));
	var min = 150;
	var n = 1;
	var plu = 2;
	var f = 0;
	var ch2 = 0;
	var ch22 = 0;
    $('#check2').css('width',bgw);
	ch22 = Number($('#check2').css('width').replace(/[^-\d\.]/g, ''));
	//alert(ch2);
	var chv = 0;
	//alert(check);
	$('#lb').click(function(){
		ch2 = Number($('#check2').css('width').replace(/[^-\d\.]/g, ''));
		var gg = '';
		if(ch2 != 750){
		chv = ch2 - 150;
		$('#check2').css('width',chv);
		gg = $('#check2').css('width');
		
		}
		$('#rb').show();
		$('#hh1').removeClass('hhf1');
		$('#hh').addClass('hhf');
		var bgl = 0;
		var bgl = Number($('#bg').css('left').replace(/[^-\d\.]/g, ''));
		var dif = 0;
		dif = bgw+bgl;
		
	
		//alert(check);
		//alert(dif);
		if(dif != check){
		
		if(ch2 != 750){
		
		var top11 = $('#bg').css("left").replace(/[^-\d\.]/g, '');
		
		
			
		if(n > 4){
			f = min - plu;
		   var ahh = Number(top11) -f;
		   check +=2;
		  
		}else{
			var ahh = Number(top11) -min;
		
		}

		
		
		
		$('#bg').animate({
			
			'left':ahh,
		
		},300,function(){
			$('#hh').removeClass('hhf');
			n++;
			
				if(ch2 == 900){
									$('#lb').hide();
				
				}
			
				//$('#lb').hide();
			
		});
		
		
		}
		
		}
		
		return false;
	
	});
	
	var mr = 150;
	$('#rb').click(function(){
		
		ch2 = Number($('#check2').css('width').replace(/[^-\d\.]/g, ''));
		var gg = '';
		if(bgw != ch2){
		chv = ch2 + 150;
		$('#check2').css('width',chv);
		gg = $('#check2').css('width');
		//alert(gg);
		}
		$('#lb').show();
		$('#hh').removeClass('hhf');
		$('#hh1').addClass('hhf1');
		var leftl = Number($('#bg').css('left').replace(/[^-\d\.]/g, ''));
		
			var mb = leftl + (mr-plu);
		
		
		if(leftl != 0 ){
		if(bgw != ch2){
		
		
		 $('#bg').animate({
				
				'left':mb,
			
			},300,function(){
				$('#hh1').removeClass('hhf1');
				
				if(bgw == (ch2+150)){
					//alert();
				
					
					$('#rb').hide();
				}
					
			});
		
		}
		}
		
		return false;
	
	});
	
	
	
	
	var add = hh * 150;
	
	
	if(add <= 750){
		
		$('#rb').hide('');
		$('#lb').hide('');
		
	}
	
	
	$('#cl').hide();
	
	
	
	//set margin for image in #postcont
	var mtop = (327-imgh)/2;
	$('#postcont img').css('margin-top',mtop);
	
	
	
	
	// function of controling the origynal size
	var orgImageH;
	var orgImageW;	
	var contentSizeH;
	var contentSizeW;	
	var imageId='';
	// set size for origynal image
	function setSize(setting,screenH,screenW){
		imageId = '';
		imageId = setting;
		contentSizeH = '';
		contentSizeW = '';
		contentSizeH = screenH;
		contentSizeW = screenW;
		
		getSize();
		
	}
	
	//get origynal image size
	function getSize(){
		orgImageH = 0;
		orgImageW = 0;
		orgImageH = Number($(imageId).css('height').replace(/[^-\d\.]/g, ''));
		orgImageW = Number($(imageId).css('width').replace(/[^-\d\.]/g, ''));
		
		checkSize();
	}
	
		
	
	//check image size against the screen 
	function checkSize(){
		
		if(orgImageH >= contentSizeH && orgImageW >= contentSizeW){
			setFullScreenSize();
		}else if(orgImageW >= contentSizeW && orgImageH < contentSizeH){
			setFullWidth();
		}else if(orgImageW < contentSizeW && orgImageH >= contentSizeH){
			setFullHeight();
		}else if(orgImageH < contentSizeH && orgImageW < contentSizeW){
			checkDifSize();
		}
	}
	
	// set width 100% and height 100% if those are more than screen's height and width
	function setFullScreenSize(){
		$(imageId).css('width','100%');
		$(imageId).css('height','100%');
	}
	
	//set width 100% and height current when origynal image width is more than screen
	function setFullWidth(){
		$(imageId).css('width','100%');
		$(imageId).css('height',orgImageH);
		setMargin();
	}
	
	//set height 100% and width current when origynal image height is more than screen
	function setFullHeight(){
		$(imageId).css('width','auto');
		$(imageId).css('height','100%');
	}
	
		
	// check propotional of size for origynal image against screnn
	var checkW = 0;
	var checkH = 0;
	function checkDifSize(){
		$(imageId).css('height','100%');	
	}

	function setMargin(){
		var h = ((contentSizeH - orgImageH)/2)-50;		
		$(imageId).css('margin-top',h);
	}
	
	

	
});











