//      __________________
//     .-'  \ _.-''-._ /  '-.
//   .-/\   .'.      .'.   /\-.
//  _'/  \.'   '.  .'   './  \'_
// :======:======::======:======:
//  '. '.  \     ''     /  .' .'
//    '. .  \   :  :   /  . .'
//      '.'  \  '  '  /  '.'
//        ':  \:    :/  :'
//          '. \    / .'
//            '.\  /.'    andrewMahon - amahon@gmail.com
//              '\/'      portfolio         -       2009

/*extern jQuery, anderewMahon */

(function ($) {
	jQuery.fn.project = function (options) {
		
		var o, $p, open, $title, $description, $year, $tools, $thumbnail
		
		o = jQuery.extend({
			open: false
		},options)
		
		$p = jQuery(this)
		open = false
		
		$title = null
		$description = null
		$year = null
		$tools = null
		$thumbnail = null
		
		function initialize() {
			initializeSelectors()
			initializeEvents()
			initializeLightbox()
			if (o.open === true) {
				openPanel(true)
			}
		}
		
		function initializeSelectors() {
			$title = $p.children(".left").children(".slide_open")
			$description = $p.children(".left").children(".description")
			$year = $p.children(".right").children(".year")
			$tools = $p.children(".right").children(".tools")
			$thumbnail = $p.children(".right").children(".thumbnail")
		}
		
		function initializeEvents() {
			$title.bind("click",_titleClickHandler)
			$thumbnail.bind("click",_thumbnailClickHandler)
		}
		
		function _titleClickHandler(e) {
			e.preventDefault()
			if (open === false) {
				openPanel(false)
			} else {
				closePanel()
			}
		}
		
		function _thumbnailClickHandler(e){
			e.preventDefault()
		}
		
		function initializeLightbox(){
			if($thumbnail){
				
			}
		}
		
		function openPanel(quick) {
			if (quick) {
				$title.children(".title").addClass("open")
				$description.show()
				$year.show()
				$tools.show()
				$thumbnail.show()
			} else {
				$title.children(".title").addClass("open")
				$description.slideDown(250)
				$tools.slideDown(250)
				$thumbnail.slideDown(250)
			}
			open = true
		}
		
		function closePanel() {
			$description.slideUp(250,function(){
				$title.children(".title").removeClass("open")
			})
			$tools.slideUp()
			$thumbnail.slideUp()
			open = false
		}
		
		initialize()
		return $p
	};
})(andrewMahon);
