function createXMLHttp() {
    var aVersions = [ "MSXML2.XMLHttp.5.0",
        "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
        "MSXML2.XMLHttp","Microsoft.XMLHttp"
    ];

    for (var i = 0; i < aVersions.length; i++) {
        try {
            var oXmlHttp = new ActiveXObject(aVersions[i]);
            return oXmlHttp;
        } catch (oError) {
            //Do nothing
        }
    }
    throw new Error("MSXML is not installed.");
}

function isNull(obj) {//Check undefined explicitly (NS6.x)
  return(obj==null)||(obj==undefined)
}


function tloada(article,target) {

   var uul = "indexx.php?article="+article+"&notarbouche=yes&uuu="+Math.random();   
   return tload(uul,target); 
}

function tloadb(section,target) {

    var ssl = "indexx.php";
    if ( section == "home") {
    
       var uul = ssl + "?section=home&notarbouche=yes&single=yes&uuu="+Math.random();
       var uxl = ssl + "?section=home&uuu="+Math.random()+"&notarbouche=yes";
     
    } else if ( section == "home1" ||  section == "home2" ||  section == "home3"  ) {
        var uul = ssl + "?section="+section+"&notarbouche=yes&templ=2&single=yes&uuu="+Math.random();
       var uxl = ssl + "?section="+section+"&notarbouche=yes&templ=2&uuu="+Math.random()+"&fullpage=yes";       
         
    } else {

       var uul = ssl + "?section="+section+"&notarbouche=yes&single=yes&uuu="+Math.random();
       var uxl = ssl + "?section="+section+"&notarbouche=yes&uuu="+Math.random()+"&fullpage=yes";

    }

    
    if(isNull(document.getElementById(target))){ 
        tload(uxl,'bodycontent');
    }
    else {
        return tload(uul,target);         
     }
}


function tload(url,target) {
		xOffset = 10;
		yOffset = 30;

$.get(url,{first_name:"Ta"},
       function(returned_data)
         {
             $("#"+target).html(returned_data);
             $("#"+target).find('.thumb_img').each( function() {
                 $(this).addcaption();	  
             });
             $("#"+target).find('img.thumb_img').click( function(e){
             	
             	   $("#preview").remove();
		             // alert((e.pageY-100) +" t-l "+(e.pageX+100)  );
		             var str = (e.pageY-100) +" t-l "+(e.pageX-160);
                 $("body").append("<div id='preview'><img src='"+ this.src +"' align='left' alt='"+this.alt+"' /></div>");								 
		             $("#preview").css("top",(e.pageY-100) + "px");
			           $("#preview").css("left", (e.pageX-160) + "px");
			           $("#preview").fadeIn("slow");
			           $("#preview").find('img').addcaption();	           
			           $("#preview").click   ( function(e){  
			           	          $("#preview").remove();
			           	 });                    
             });
             $("#"+target).find('img.thumb_img').hover( function(){
             	
      	
      	     // var oWidth = $(this).outerWidth()+'px';
             // var oHeight = $(this).outerHeight()+'px';
      	     var oWidth = $(this).outerWidth()*3+'px';
             var oHeight = $(this).outerHeight()*3+'px';
        
             //You could always multiply the multiplier if you want to make the image adjust to a larger size.  
             // Keep in mind though it will get more blurry
             var mpx = (oWidth / oHeight);
             // alert(oWidth + " "+oHeight);
             $(this).css("z-index","999");
             $(this).stop().animate({position: 'absolute',
                  width: oWidth,
                  zIndex: 999
                  
               },1000);}   
   
              , function(){
   	          $(this).css("z-index","1");
              $(this).stop().animate({position: 'relative',
                     width: '128px',
                     zIndex: -1
                     
               },1000);
              });              
         });

}

function tloads(url,target) {
	  
    // native XMLHttpRequest object
    // document.getElementById(target).innerHTML = 'sending...';
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        // req.setRequestHeader("Content-Type", "text/html; charset=windows-1256");
        req.onreadystatechange = function() {tDone(target);};
                
        
        req.open("GET", url, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = createXMLHttp();
       
        if (req) {
            req.onreadystatechange = function() {tDone(target);};
            req.open("GET", url +"&sid=" + Math.random(), true);
            req.send();
        }
    }
} 

function tDone(target) {
    // only if req is "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            
            results = req.responseText;
            // alert(results );
            window.document.body.scrollTop = 0;
            window.document.documentElement.scrollTop = 0;
            document.getElementById(target).innerHTML = results;
            document.getElementById("photo_gallery");
            
   $("#photo_gallery > img").hover( function(){
   	alert("hover");
   $(this).stop().animate({
            width: '256px',
            height: '256px'
      },1000);}   
   
   , function(){
   $(this).stop().animate({
          width: '128px',
          height: '128px'
     },1000);
  }); 
              
        } else {
            document.getElementById(target).innerHTML="jah error:\n" +
                req.statusText;
        }
    }
}

/* 
	jQuery addCaption plugin
	Copyright 2008 by Paul Boutin 
	Licensed under the Creative Commons Attribution 3.0 license
	Version 1.0.0
	http://www.redsgn.com/category/jquery/
	
*/
(function($){
 $.fn.addcaption = function(options) {
  var defaults = {
	  bgcolor:'#fff',
	  fontcolor:'#333',
	  font:'Arial, Helvetica, sans-serif',
	  fontsize:'10px;',
	  margin:'margin:5px;',
	  align:'display:block;float:right;',
	  width:'width:auto;',
	  border:'border:1px solid #000;'
  };
  var options = $.extend(defaults, options);
    
  return this.each(function() {
   if($(this).attr('alt')){
	   var margin = options.margin;
	   if($(this).attr('vspace') != -1 && $(this).attr('hspace') != -1){
	   		margin = 'margin:'+$(this).attr('vspace')+'px '+$(this).attr('hspace')+'px;';
			$(this).removeAttr('vspace').removeAttr('hspace');
	   }else if($(this).attr('vspace') != -1){
			margin = 'margin:'+$(this).attr('vspace')+'px 0px;';
			$(this).removeAttr('vspace');
	   }else if($(this).attr('hspace') != -1){
			margin = 'margin:0px '+$(this).attr('hspace')+'px;';
			$(this).removeAttr('hspace');
	   }
	   var align = options.align;
	   if($(this).attr('align') && ($(this).attr('align').toLowerCase() == 'right' || $(this).attr('align').toLowerCase() == 'left')){
	   		align = 'display:block;float:'+$(this).attr('align').toLowerCase()+';';
	   }
	   if($(this).attr('align')){
	   		$(this).removeAttr('align');
	   }
	   var width = options.width;
	   if($(this).attr('width')){
	   		width = 'width:'+$(this).attr('width')+'px;';
	   }
	   var border = options.border;
	   if($(this).attr('border')){
	   		border = 'border:'+$(this).attr('border')+'px solid #000;';
			$(this).removeAttr('border');
	   }
	   $(this).attr('style','margin:auto;border:none;');
	   $(this).wrap('<span style="'+border+'background-color:#fff;'+align+''+margin+'padding:0px;text-align:center;'+width+'"></span>');   
	   $(this).parent('span').append('<span style="display:block;text-align:center;padding:2px;background-color:#fff;color:#333;font-family:'+options.font+';font-size:'+options.fontsize+'width:'+(parseInt($(this).attr('width'))-4)+'px;">' + $(this).attr('alt') + '</span>');
   	   if($(this).parent('span').parent('a')){
			if($.browser.msie){
				$(this).parent('span').attr('style',$(this).parent('span').attr('style') + 'cursor:hand;');
				$(this).parent('span').parent('a').attr('style','text-decoration:none;cursor:hand;');
			}else{
				$(this).parent('span').attr('style',$(this).parent('span').attr('style') + 'cursor:pointer;');
				$(this).parent('span').parent('a').attr('style','text-decoration:none;cursor:pointer;');
			}
	   }
	}
  });
 };
})(jQuery);


