/* Creative page anchor highlighter */

function clearClass() {
  $("#jumpdesign").removeClass("design_selected");
	  
  $("#jumpinteractive").removeClass("design_selected");
	  
  $("#jumpadvertising").removeClass("design_selected");
  
  $("#jumpbranding").removeClass("design_selected");
}


$("document").ready(function() {
	
	$(".jumplink").click(function() {
	 
    clearClass();
    
    var obj=$(this); // which link was clicked?
    var name=obj.attr("href"); // get the href attribute's value - which should correspond to the id name of the div to highlight
    $(name).addClass("design_selected"); // add to that item the highlight class
	 
	});
	
});


/* Creative page portfolio preview */
/* from: http://www.malsup.com/jquery/cycle */

$(function() {
  // $('#pause').click(function() { $('#folio_preview_images').cycle('pause'); return false; });
  // $('#play').click(function() { $('#folio_preview_images').cycle('resume'); return false; });
  
  $('.folio_mini').hover(
    function() { $('#controls').fadeIn(); },
    function() { $('#controls').fadeOut(); }
  ); 

  $('#folio_preview_images').cycle({
    fx: 'scrollHorz',
    speed: 600,
    timeout: 3000,
    next: '#next',
    prev: '#prev'
  });
});


/* Creative page full portfolio */
/* from: http://www.sohtanaka.com/web-design/fancy-thumbnail-hover-effect-w-jquery */

$(document).ready(function(){

//Larger thumbnail preview 

$("ul#portfolio_full li").hover(function() {
	$(this).css({'z-index' : '99'});
	$(this).find('img').addClass("hover").stop()
		.animate({
			marginTop: '0px', 
			marginLeft: '0px', 
			top: '50%', 
			left: '50%', 
			width: '870px', 
			height: '490px',
			padding: '0px' 
		}, 500);
	
	} , function() {
	$(this).css({'z-index' : '10'});
	$(this).find('img').removeClass("hover").stop()
		.animate({
			marginTop: '0', 
			marginLeft: '0',
			top: '0', 
			left: '0', 
			width: '270px', 
			height: '152px', 
			padding: '0px'
		}, 400);
});

//Swap Image on Click
	$("ul#portfolio_full li a").click(function() {
		
		var mainImage = $(this).attr("href"); //Find Image Name
		$("#main_view img").attr({ src: mainImage });
		return false;		
	});
 
});

/* Wait Function (used for AJAX portfolio below */
/* from:  http://docs.jquery.com/Cookbook/wait  */

$.fn.wait = function(time, type) {
  time = time || 1000;
  type = type || "fx";
  return this.queue(type, function() {
    var self = this;
    setTimeout(function() {
        $(self).dequeue();
    }, time);
  });
};


/* Full Portfolio AJAX */
/* by tsisti 10/8/09 */

$("document").ready(function() {

  $("#portfolio_full img").fadeIn(2000);

  function ajaxgo(thethumbid) {
	  var ajaxload = "imagelist.html ." + thethumbid; // construct the ajax call; file name plus the class name that matches the id from the previous step
	  $("#portfolio_full").load(ajaxload, function() { // execute the call
	    $("#portfolio_full img").wait().fadeIn(2000); // fade in the new image, which is supporessed by default by CSS
	  });
  };

	$(".portthumb").click(function() { // click on any thumbnail with this class...
	  $(".portthumb").removeClass("selected");
	  $(this).addClass("selected");
	  var thumbid = $(this).attr("id"); // determine the id of the thumbnail that was clicked
	  $("#portfolio_full img").fadeOut(500, function() { // fade out the current featured image, then execute the ajax call
	    ajaxgo(thumbid); // we do the callback like this because we can't pass arguments in line; we must create an anonymous function that then executes the function with arguments; see:   http://docs.jquery.com/Tutorials:How_jQuery_Works#Callback_and_Functions
	  });
	});
	
});


/* Slider for AJAX piece */
/* from: http://www.switchonthecode.com/tutorials/using-jquery-slider-to-scroll-a-div  */

$(document).ready(function(){
  $("#folio_slider").slider({
    animate: true,
    change: handleSliderChange,
    slide: handleSliderSlide
  });
});

function handleSliderChange(e, ui)
{
  var maxScroll = $("#portfolio_full_thumbs").attr("scrollWidth") -
                  $("#portfolio_full_thumbs").width();
  $("#portfolio_full_thumbs").animate({scrollLeft: ui.value *
     (maxScroll / 100) }, 1000);
}

function handleSliderSlide(e, ui)
{
  var maxScroll = $("#portfolio_full_thumbs").attr("scrollWidth") -
                  $("#portfolio_full_thumbs").width();
  $("#portfolio_full_thumbs").attr({scrollLeft: ui.value * (maxScroll / 100) });
}
