function flickr_init(variable)
{
	var $j = jQuery.noConflict();
	var url = 'http://api.flickr.com/services/feeds/photos_public.gne?id=' + variable.userID + '&lang=en-us&format=json&jsoncallback=?';
	$j.getJSON(url, function(data){
		  var items = data.items;
          $j.each(data.items, function(i,item){		  	
		  	if (item.title !== cookie({ type: 'get', name: 'image_title' })) {
				var id = item.link.replace('.', '').replace('.', '').replace('/', '').replace('/', '').replace('/', '').replace('/', '').replace('/', '').replace('/', '').replace(':', ''), title = item.title, description = item.description;
				$j('<img/>').attr('src', item.media.m).appendTo('#' + variable.divID).attr('id', id).attr('alt', item.title).attr('class', 'portfolio_thumb').click(function(items, title, description){
					return function(){
						flickr_click(items, title, description);
					}
				}(items, title, description));
				cookie({ type: 'add', name: 'image_title', value: title })
			}
          });
    });
}

function flickr_click(items, title, description)
{
	var 
		$j = jQuery.noConflict(),
		docHeight = document.height || document.body.offsetHeight,
		portfolio_items = [],
		i = 0,
		j = 0;
	$j('<div/>').attr('id', 'lightbox_window').appendTo('body').css('height', docHeight).click(function(){
		return function(){
			$j('#lightbox_window').remove();
			$j('#lightbox_container').remove();
		}
	}());
	$j('<div/>').attr('id', 'lightbox_container').appendTo('body');
	$j('<h2/>').html(title).appendTo('#lightbox_container');
	$j('<p/>').html(description).appendTo('#lightbox_container');
	$j('#lightbox_container p p').remove(":contains('posted a photo:')");
	$j('p a img').css('display', 'none');
	$j('<div/>').attr('id', 'lightbox_close').appendTo('#lightbox_container').click(function(){
		return function(){
			$j('#lightbox_window').remove();
			$j('#lightbox_container').remove();
		}
	}());
	$j('<div/>').attr('id', 'cycle_photos').appendTo('#lightbox_container');
	while (i < items.length)
	{
		if (items[i].title == title)
		{
			portfolio_items[j] = items[i].media.m.replace('_m', '');
			$j('<img/>').attr('src', items[i].media.m.replace('_m', '')).attr('id', 'img_' + j).attr('class', 'portfolio_image_large').appendTo('#cycle_photos');
			j++;
		}
		i++;
	}
	$j('#cycle_photos').cycle({ 
	    fx:    'fade', 
	    speed:  2500,
		timeout:  9000,
		next:   '#cycle_photos',
	 });
	fixHeight();
}

function fixHeight()
{
	try {
		if (document.getElementById('cycle_photos') && document.getElementById('cycle_photos').firstChild.style.height !== '') {
			document.getElementById('cycle_photos').style.height = document.getElementById('cycle_photos').firstChild.style.height;
		}
		else if (document.getElementById('cycle_photos') && document.getElementById('cycle_photos').children[1].style.height !== '') {
			document.getElementById('cycle_photos').style.height = document.getElementById('cycle_photos').children[1].style.height;
		}
		else if (document.getElementById('cycle_photos') && document.getElementById('cycle_photos').children[2].style.height !== '') {
			document.getElementById('cycle_photos').style.height = document.getElementById('cycle_photos').children[2].style.height;
		}
		else {
			setTimeout("fixHeight();", 100);
		}
	}
	catch (e) {
		setTimeout("fixHeight();", 100);
	}

}

