
/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function actualLoadPopup(srcimage, titlepiece, textpiece){
		/*$("#popupContent").load(src);*/
		//alert (titlepiece+", "+ textpiece);
		$('#replace_image').attr('src', srcimage);
		//$('#'+TitleName).text(srcimage);
		$('#TitleName').text(titlepiece);
		$('#textName').text(textpiece);

		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
}
function loadPopup(src, titlepiece, textpiece){
	//loads popup only if it is disabled
	if(popupStatus==0){
		actualLoadPopup(src, titlepiece, textpiece);
	}else{
		disablePopup();
		actualLoadPopup(src, titlepiece, textpiece);
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	var sam;
	var doslides="yes";
	var numbertimes=0;
	//first will will resize the images.
      //  alert("we are going to attempt to resize the images");
  if( doslides =="yes"){
	  
	$sam=$.timer(1000, function (timer) {
		if(numbertimes< 7){
		//alert ("started timer");
		gallery();
		}
  		/* end timer  function*/
 	 });
	
  }
	function gallery(){	
	//alert("we are attempting to resize the images");
	numbertimes++;
	//if(numbertimes>4){
		//alert ("we are over 4");
		
	//	$(document).stopTime();
	//}
	$('.thumb_size').each(function() {
        //alert("we are attempting to resize the images");
		var maxWidth = 150; // Max width for the image
        var maxHeight = 150;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
        var width = $(this).width();    // Current image width
        var height = $(this).height();  // Current image height
		
 
        // Check if the current width is larger than the max
        if(width > maxWidth){
            ratio = maxWidth / width;   // get ratio for scaling image
            $(this).css("width", maxWidth); // Set new width
            $(this).css("height", height * ratio);  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        }
 
        // Check if current height is larger than max
        if(height > maxHeight){
            ratio = maxHeight / height; // get ratio for scaling image
            $(this).css("height", maxHeight);   // Set new height
            $(this).css("width", width * ratio);    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
        }
    });
   }

  $('.thumb_size').click(function(){
		var content_src = $(this).attr("src");
		var titlepiece = $(this).attr("alt");
		var textpiece = $(this).attr("title");
		//alert(titlepiece + " " +textpiece );
//		alert ("We should be able to get some information");
		if(popupStatus!=0){
			disablePopup();
		}
		centerPopup();
		//load popup
		loadPopup(content_src, titlepiece, textpiece );
  
  });
 
//LOADING POPUP
	//Click the button event!
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

//******************************** //
//	Adding and subracting content  //
//******************************** //
$(".answer").slideUp(500);
$(".question").click(function(){
	//alert ("found a question " + this.name + " title:"  + this.title);
	$(".answer").slideUp(500);
	$(".question"+this.title).slideDown(500);
	
	$("#answer"+this.title).slideDown(500);
	$("#question"+this.title).slideUp(500);
		//id="answer1" class="question"
});
$(".less").click(function(){
	//global titlet;
	//titlet=this.title;
	//alert ("found a less " + this.name + " title:"  +  titlet);
		$("#answer"+this.title).slideUp(500);
		$("#question"+this.title).slideDown(500);
		//id="answer1" class="question"
});

});
	$(document).ready(function(){
  var currentPosition = 0;
  var slideWidth = 150;
  var slides = $('.slide');
  var numberOfSlides = slides.length;
  var sam;
  var doslides ="yes";
  
    $('#slidesContainer').css('overflow', 'hidden');



 
  // Wrap all .slides with #slideInner div
  slides
  .wrapAll('<div id="slideInner"></div>')
  // Float left to display horizontally, readjust .slides width
  .css({
    'float' : 'left',
    'width' : slideWidth
  });


  // Set #slideInner width equal to total width of all slides
  $('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert left and right arrow controls in the DOM
  $('#slideshow')
    //.prepend('<span class="control" id="leftControl">Move left</span>')
    //.append('<span class="control" id="rightControl">Move right</span>');
  manageControls(currentPosition);
  //$('#content').append(links);
  //$('.content').append(links);
  //alert("hmm");
  
//  	$("li.picturejump").css('text-decoration', 'none');

  //alert("hello! " + numberOfSlides + " " + currentPosition + " " +  doslides);
  //$sam=setInterval('gallery()',6000);
  // Hide left arrow control on first load
  //var $sams=window.setInterval('gallery()',6000);
  if(numberOfSlides>1 && doslides =="yes"){
	  
	$sam=$.timer(6000, function (timer) {
	//alert ("started timer");
	gallery();
/*	$("li.picturejump")
    .bind('click', function(){
    // Determine new position
	var jump;
	jump =$(this).attr("title");
	//alert("we want to jump to " +jump);
//      currentPosition = ($(this).attr('id')=='rightControl')
 //   ? currentPosition+1 : currentPosition-1;

      // Hide / show controls
      manageControls(jump);
	  slideshowjump(jump);
	  timer.stop();
      // Move slideInner using margin-left
//      $('#slideInner').animate({
 //       'marginLeft' : slideWidth*(-currentPosition)
  //    });
   });*/
	//timer.stop();
  /* end timer  function*/
  });
	
  }
/*							


  // Create event listeners for .controls clicks
  $('.control')
    .bind('click', function(){
    // Determine new position
      currentPosition = ($(this).attr('id')=='rightControl')
    ? currentPosition+1 : currentPosition-1;

      // Hide / show controls
      manageControls(currentPosition);
      // Move slideInner using margin-left
      $('#slideInner').animate({
        'marginLeft' : slideWidth*(-currentPosition)
      });
   });
*/ 
function gallery(){
	if(doslides =="yes"){//alert("attempting to run gallery");
	currentPosition = (currentPosition==(numberOfSlides-1)) ? 0 : currentPosition+1;

    //alert("hello! " + numberOfSlides + " " + currentPosition);
	
	$('#slideInner').animate({
        'marginLeft' : slideWidth*(-currentPosition)
    });
	}
}
$("li.picturejump").click(function(){
	//alert ("found a sub nav");								   	
	var jump;
	doslides ="no";
	//timer.stop();
	jump =$(this).attr("title");
	//alert ("found a sub nav with title: " + URL);
	//alert ("found a sub nav " + jump);
	//if(jump == currentPosition){
		slideshowjump(jump);
	//}
	
	//$sam=0;
	
/*	//alert ("Clicked on an attorney link test " + URL + " 2");

*/

});

 // manageControls: Hides and shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
    if(position==0){ $('#leftControl').hide() }
    else{ $('#leftControl').show() }
    // Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ $('#rightControl').hide() }
    else{ $('#rightControl').show() }
    }
function slideshowjump(step){
/*	var newstep;
	currentPosition=currentPosition+1;
	if(currentPosition>step){
		newstep=step-currentPosition;
//		newstep=newstep-1;
	}else{
		newstep=step-currentPosition;
//		newstep=newstep+1;
	}
	//alert(newstep + " stp: " +step + " " + currentPosition);
*/	
	var teststep=step-1;
	if(teststep >-1){
		$('#slideInner').animate({
        'marginLeft' : slideWidth*(-teststep)
    	});
	}else{
	}
	currentPosition=teststep;

/*	$('#slideInner').animate({
        'marginLeft' : slideWidth*(-0)
    });
//  :underline;
	//  text-decoration:none;

    
	//alert ("request to go to " + step);

	if(step>1){
		step=step-1;
		$('#slideInner').animate({
        'marginLeft' : slideWidth*(-step)
    	});
	}
	*///$("li.picturejump").css('text-decoration', 'none');
	//$("#"+step).css('text-decoration', 'underline');
	//$('.links'+i).css('text-decoration', 'underline');
	

/*	baseslideshow();
		for (i=1;i<step;i++){
			gallery();
		}
*/	}
  
/* end document ready */
  });  



