var GB_ANIMATION = true;

var id_curr=0;
var id_prev=0;
var id_next=1;
var objImagePreloader = new Image();


function ajaxRequest(urli,datai) {
	var aj = $.ajax({
		  type: "get",
		  url: urli,
		  data: datai,
		  dataType: "json",
		  success: getResponse,
		  beforeSend: showLoad
	});
}



function getResponse(oReq) {
	var json = oReq;
	if (json.status=="1"){
		id_curr=json.curr;
		id_prev=json.prev;
		id_next=json.next;
		

		objImagePreloader.onload = function() {
			$('#big_img').attr('src',objImagePreloader.src);
			objImagePreloader.onload=function(){};
			$('#ico-loading').hide();
			$('#big_img').show();
			//$('a.work_box').lightBox();
		}

		
		objImagePreloader.src = json.photo;
		$('#big_img').attr('src',objImagePreloader.src);
		//$('#pr_main_img').attr('href',json.photo_big);
		//$('#pr_main_img').attr('title',json.title);
		num_curr = parseInt(json.curr)+1;
		$('#content').html('<img src="/images/steps/step'+num_curr+'.png" id="step_num" alt=""/>'+json.descr);
		
				
		if (id_prev==0&&id_curr==0) $('a.pr-prev').addClass('pr-prev-disabled');
		else $('a.pr-prev').removeClass('pr-prev-disabled');
		
		if (id_next==0) $('a.pr-next').addClass('pr-next-disabled'); 
		else $('a.pr-next').removeClass('pr-next-disabled');
		
	}else{

	}
}


function showLoad () {
	$('#big_img').hide();
	$('#ico-loading').show();
	
}


function getPrev(){
	getImage(id_prev);
}

function getNext(){
	getImage(id_next);
}

function getImage(id){
	$('img.curr_img').css('opacity','0.5');
	$("img.curr_img").mouseover(
		function(){
			$(this).animate({ opacity: 1 }, 500 );
		}
	);
	$("img.curr_img").mouseout(
		function(){
			$(this).animate({ opacity: 0.5 }, 500 );
		}
	);
	$('.thumb_img').removeClass('curr_img');
	$('#img_'+id).addClass('curr_img');
	$('img.curr_img').css('opacity','1');
	$('img.curr_img').unbind("mouseover");
	$('img.curr_img').unbind("mouseout");
	


	
	ajaxRequest('/photos/'+type+'/'+id_link+'/'+id+'/', '');
		
	
	
}

	
	function load() {
		doLoad();
		mArray.push("39.18829;-106.822901;<span style='color:#000'><b>Hotel Durant</b><br/>122 East Durant<br/>Aspen, Colorado  81611<br/>p  877.438.7268<br/>f  970.925.8789</span>");
		addMarkers();
	}
	
    function doLoad() {
		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById("map"));
			//map.setCenter(centerPoint, 16);
			map.addControl(new GScaleControl());
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
		}
    }

	function addMarkers() {
		if (mArray.length) {
			var bounds = new GLatLngBounds();
			for (n=0 ; n < mArray.length ; n++ ) {
				var mData = mArray[n].split(';');
				var point = new GLatLng(mData[0],mData[1]);
				bounds.extend(point);
				var marker = createMarker(point, mData[2]);
				
				map.addOverlay(marker);
				//map.openExtInfoWindow(point,
                //           '<div style="width:100px;font-size:0.8em;">' + mData[2]+  '</div>');
						   map.openInfoWindow(point,
                           '<div style="width:170px;font-size:0.8em;">' + mData[2]+  '</div>', {maxWidth:150});
			}
			map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)); 
		}
	}
	
	function createMarker(point, title) {
		var marker = new GMarker(point,{title:title});
		GEvent.addListener(marker, "click", function() {
		marker.openInfoWindow(
			'<div style="width:100px;font-size:0.8em;">' + title+  '</div>',{maxWidth:150});
		});
		return marker;
	}


function mnuOn(id_mnu){
	jQuery('#menu_but_'+id_mnu).attr('src',objOnMenuMainImageArray[id_mnu].src);
	return true;
}

function mnuOff(id_mnu){
	jQuery('#menu_but_'+id_mnu).attr('src',objOffMenuMainImageArray[id_mnu].src);
	return true;
}

	
jQuery (document).ready(function(){
		$('.media_block').media();
		$.ifixpng('/images/pixel.gif');
		$('img[src$=.png]').ifixpng();
		$('a.work_box').lightBox();
		$('#scroll_pane').jScrollPane({scrollbarWidth:8});
		$('.ttip').tooltip({ 
			track: true, 
			delay: 0, 
			showURL: false, 
			showBody: " - ", 
			fade: 100 
		});
		$('.modal-link').click(function (e) {
			$('#basic-modal-content').modal();
			return false;
		});
		
		$("a.greybox").click(function(){
			var t = this.title || $(this).text() || this.href;
			GB_show(t,this.href,400,400);
			return false;
        });
		
		$('img.thumb_img').css('opacity','0.5');
		$("img.thumb_img").mouseover(
			function(){
				$(this).animate({ opacity: 1 }, 500 );
			}
		);
		$("img.thumb_img").mouseout(
			function(){
				$(this).animate({ opacity: 0.5 }, 500 );
			}
		);
		$('img.curr_img').css('opacity','1');
		$('img.curr_img').unbind("mouseover");
		$('img.curr_img').unbind("mouseout");


});
	