

/*------------work.js----------*/

reg.postSetup(function() {
	// carousel values
  var scroll    = 7;
	var itemcount = 0;
	var itemstart = 1;
	
	// find "on" item
	$('#mycarousel').find('li').each(function(i) {
		if ($(this).attr('class') == 'on') { id = i; } 
		itemcount = itemcount + 1;
	});
	
	// center "on" item
	if (id) {
		boundary = Math.floor(scroll / 2);
		if (id + 1 <= boundary) {
			itemstart = 1; 
		} else if (id + 1 >= itemcount - boundary) {
			itemstart = itemcount - boundary;
		} else {
			itemstart = id + 1 - boundary;
		}
	}
	
	// set carousel
	jQuery('#mycarousel').jcarousel({
		scroll:scroll,
		size:itemcount,
		start:itemstart
	});
	 
	/*TOOLTIPS*/
	// apply tooltips to thumbs
	$('#work-thumbs a').tooltip({
		track:true, 
    delay:0, 
    showURL:false, 
    opacity:1
	});
	 
	 
	var orig_content = '';
	var new_content  = '';
		
	/*THUMB CLICK FX*/
	// loop all <a tags
	$('#work-thumbs *').find('a').click(function() {
  	// remove 'on' class from all links
		$('#work-thumbs').find('li').each(function(i) {
			 if ($(this).attr('class') == 'on' || $(this).attr('class') == 'first on') {
				$(this).removeClass('on');
			} 
		});
		
	  // get id of clicked element from id="link#"
		var id = $(this).attr('id').split('link').pop();
		
		//highlight thumb
		$('#bg' + id).addClass('on'); 

		// call ajax script to get data
		$.getJSON('/ajax/getWorkDetail?id=' + id, function(response) {
			if (response.data) {
			 	$('#portfolio-title').html(response.data.title);
			 	$('#portfolio-text').html(response.data.text);
	      $('#image-large').attr('src', '/images/content/' + response.data.image_lg);
				/*
				// TO_DO - find out how fx should be implemented
				// get code in div
				if (orig_content) {
				  orig_content = new_content;
				} else {
					orig_content = $('#main-image-holder').html();
				}
				
				new_content = '<img src="/images/content/' + response.data.image_lg + '" alt="' + response.data.title + '" title="' + response.data.title + '" />';
				$('#main-image-holder').html(orig_content + new_content);
	
				$('#main-image-holder').cycle('fade');
				$('#main-image-holder').cycle({ 
					fx:'shuffle', 
			    speed:1000, 
			    next:'#main-image-holder', 
			    timeout:10 
				});
				*/
			}
  	});
		
		// return false so page doesnt jump to top
		return false;
	});
});

