
$(document).ready(function() {

	if ($('#cart-toolbox').length){
		$('#cart_data').hide();
		$('#cart-toolbox').hoverIntent({timeout:800,over:showMenu,out:hideMenu});
		// initial population for the cart box.
		$.get('http://t413.com/index.php', {"p":"ajax","type":"addtocart","r": "ajax"}, function(data){ updateCartToolbox(data)}, "text");
	}
	

	/***initial searchbox population and clear***/
	if ($('#search_input').length) {
		$('#search_input')[0].value = "Search" ;	//initial fill
		$("#search_input").focus(function() {		//clear on focus
			if ($(this).val() == "Search") {
				$(this).val("");
			}
		});
		$("#search_input").blur(function() {		//refill on blur if empty
			if ($(this).val() == "") {
				$(this).val("Search");
			}
		});
		/***add check all/clear all function***/
		$("#checkAllAuto").toggle(	//add the atrribute checked
			function() { $("#searchextrashow INPUT[type='checkbox']").attr('checked','checked'); },
			function () { $("#searchextrashow INPUT[type='checkbox']").removeAttr("checked"); }
		);
	};
    
	/***index comment box hide and show***/
	$('#nessassary_info').hide();		//hide initially
	$("#commentform textarea").focus(function() {	
		$('#nessassary_info').slideDown('fast');	//show with slide effect
		$('#nessassary_info #code')[0].value = "<-captcha" ;
	});
	$("#nessassary_info #cancel").click(function() {
		$('#nessassary_info').slideUp('fast');
	});
	
	/*** clear defaults***/
	$("#nessassary_info #author_name").focus(function() {
		if ($(this).val() == "name") { $(this).val(""); }
	});
	$("#nessassary_info #author_name").blur(function() {
		if ($(this).val() == "") { $(this).val("name"); }
	});
	$("#nessassary_info #code").focus(function() {
		if ($(this).val() == "<-captcha") { $(this).val(""); }
	});
	$("#nessassary_info #code").blur(function() {
		if ($(this).val() == "") { $(this).val("name");}
	});
    
	/////  EXIF hide function   //////
	jQuery.fn.showonly = function() {
		$('td.label').parent().hide();				//hide all of the tr's
		var keep_arr = ["Shutter Speed:","Aperture:","Focal Length:"];		//spesify the ones to keep
		$(this).each(function(){
			var thislabel = $(this).html();
			for (i=0; i < keep_arr.length; i++){
			if (thislabel == keep_arr[i]){ 
					$(this).parent().show();		//now unhide those
				}
			}
		});
	};

	/////  EXIF Show/hide events  //////
	if ($('#exif_info').length) {
		$('#show_all').click(function() {
			if ($('#show_all').text() == "more"){
				$('td.label').parent().show();
				$('#show_all').text('less');
			}
			else {
				$('td.label').showonly();
				$('#show_all').text('more');
			}
		});
		$('td.label').showonly();
	};

    
	/////  More than a couple comments fun   //////
	var myclasses = $('.single_comment');
	var mynum = myclasses.length;
	if ( myclasses.length > 3 ) {
			myclasses.each(function(i){
				if (i == 0|i+1==mynum){}
				else { $(this).hide(); }
				if (i==0) { $(this).append('<div id="showmore">Show '+(mynum-2)+' more</div>'); }
			});
		$('#showmore').click(function() {
				$('.single_comment').slideDown('fast');
				$('#showmore').slideUp('fast');
		});
	};
	
	/////  Album show little charts!!   //////
	if ($('#show_graphs').length){
		$('#show_graphs').click(function() {
			if ($('#show_graphs').text() == "Show More Info"){
				if ( $('#album_graphs').length != 0 ) {
					$('#album_graphs').slideDown('fast');$('#show_graphs').text('Hide More Info');
				}
				else {
					$('#show_graphs').after('<div id="album_graphs" style="display:none;"><div id="ISO_graph"></div><div id="flash_graph"></div></div>');
					$('#ISO_graph').load('/index.php?p=ajax&type=graph&id='+thisAlbID+'&kind=EXIFISOSpeedRatings','',function() {
						$('#flash_graph').load('/index.php?p=ajax&type=graph&id='+thisAlbID+'&kind=EXIFFlash','',function() {
							$('#album_graphs').slideDown('fast');
							$('#show_graphs').text('Hide More Info');
						});
					});
				}
			}
			else {
				$('#album_graphs').slideUp('fast');
				$('#show_graphs').text('Show More Info');
			}
		});
	};
    
    
	/////  Slideshow loading  //////
	if ($('#slideshows div').length){
		$('#slideshows div').click(function(event) {
		    event.preventDefault();
		    var thishref = $(this)[0].children[0].href;
		    //$(this).unbind("click");
		    $('#slideshow-player').html('');
		    $('#slideshow-player').animate({ width: "650px",height: "540px"}, 600, function(){
			$('#slideshow-player').html('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="620" height="533" id="soundslider" align="middle"><param name="allowScriptAccess" value="always" /><param name="movie" value="'+thishref+'soundslider.swf?size=1&format=xml" /><param name="quality" value="high" /><param name="allowFullScreen" value="true" /><param name="menu" value="false" /><param name="bgcolor" value="#FFFFFF" /><embed src="'+thishref+'soundslider.swf?size=1&format=xml" quality="high" bgcolor="#FFFFFF" width="620" height="533" name="soundslider" align="middle" menu="false" allowScriptAccess="always" type="application/x-shockwave-flash" allowFullScreen="true" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
		    });
		});
	};


	/////  Admin Crop mode  //////
	if ($('#admin').length && $('#images .image').length){
		$('#right_info').append('<a id="cropMode">Admin Crop Mode</a> ');
		$('#cropMode').click(function(event) {
			$("#images .image a").animate({ backgroundColor: "#ffdfb8" }, 400);
			//$("#images .image a").html(" ");
			$('#images .image a').each(function(){
				this.href = this.href.replace(/t413.com\/(([^\/|\.]+\/)+)([^\.]+.jpg).php/gi,"t413.com/zp-core/admin-thumbcrop.php?a=$1&i=$3");
			});
		});
		
		$('#right_info').append('<a id="tagMode">Admin TAG Mode</a> ');
		$('#tagMode').click(function() {
			$("#images .image a").animate({ backgroundColor: "#ffdfb8" }, 400);
			$('#images .image a').each(function(){
				this.href = this.href.replace(/t413.com\/(([^\/|\.]+\/)+)([^\.]+.jpg).php/gi,"t413.com/index.php?p=ajax&type=tagThis&alb=$1&imag=$3");
			});
		});
	};
	
});

function showMenu(){ $('#cart_data').slideDown(100); }
function hideMenu(){ $('#cart_data').slideUp(100); }

function updateCartToolbox(data){
	if (data != "none"){
		cartData = JSON.parse(data);
		/*JSON.parse*/
		
		$('#jsAdded').html("Latest added image: <div id=\"latestAdded\"></div>");
		$('#latestAdded').append('<a href="'+cartData.latestImage.data.pageURL+'">'+
					 '<img src="'+cartData.latestImage.data.thumbURL+'" />'+
					 '('+cartData.latestSize+')</a>'); //cartData.latestImage.data.title
	}
}

/* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+ * <http://cherne.net/brian/resources/jquery.hoverIntent.html> */
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

//jQuery Color Animations plugin
(function(jQuery){jQuery.each(['backgroundColor','borderBottomColor','borderLeftColor','borderRightColor','borderTopColor','color','outlineColor'],function(i,attr){jQuery.fx.step[attr]=function(fx){if(fx.state==0){fx.start=getColor(fx.elem,attr);fx.end=getRGB(fx.end)}fx.elem.style[attr]="rgb("+[Math.max(Math.min(parseInt((fx.pos*(fx.end[0]-fx.start[0]))+fx.start[0]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[1]-fx.start[1]))+fx.start[1]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[2]-fx.start[2]))+fx.start[2]),255),0)].join(",")+")"}});function getRGB(color){var result;if(color&&color.constructor==Array&&color.length==3)return color;if(result=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))return[parseInt(result[1]),parseInt(result[2]),parseInt(result[3])];if(result=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))return[parseFloat(result[1])*2.55,parseFloat(result[2])*2.55,parseFloat(result[3])*2.55];if(result=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))return[parseInt(result[1],16),parseInt(result[2],16),parseInt(result[3],16)];if(result=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))return[parseInt(result[1]+result[1],16),parseInt(result[2]+result[2],16),parseInt(result[3]+result[3],16)];return colors[jQuery.trim(color).toLowerCase()]}function getColor(elem,attr){var color;do{color=jQuery.curCSS(elem,attr);if(color!=''&&color!='transparent'||jQuery.nodeName(elem,"body"))break;attr="backgroundColor"}while(elem=elem.parentNode);return getRGB(color)};var colors={white:[255,255,255],}})(jQuery);
