
var id_curr=0;
var id_prev=0;
var id_next=1;
var objImagePreloader = new Image();
var gal_delay = 3000;

function ajaxRequest(urli,datai) {
	var aj = $.ajax({
		  type: "get",
		  url: urli,
		  data: datai,
		  dataType: "json",
		  success: getResponse,
		  beforeSend: showLoad,
		  async: false

	});
}



function getResponse(oReq) {
	var json = oReq;
	
	if (iTimer) {
		clearTimeout(iTimer);
		iTimer = 0;
	}
	
	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();
			$('#pr_main_img').show();
			$('a.work_box').lightBox();
			if (json.stop=='0') iTimer = setTimeout("getNext()", gal_delay);
		}

		$('#big_img').attr('src',json.photo);
		objImagePreloader.src = json.photo;
		$('#pr_main_img').attr('href',json.photo_big);
		$('#pr_main_img').attr('title',json.title);
		
				
		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 () {
	$('#pr_main_img').hide();
	$('#big_img').hide();
	$('#ico-loading').show();
	
}


function getPrev(action){
	getImage(id_prev,action);
}

function getNext(action){
	getImage(id_next,action);
}

function getImage(id,action){
	if(action==undefined)action=0;
	ajaxRequest('/photos/'+type+'/'+id_link+'/'+id+'/'+action+'/', '');
		
	/*if (id!=0) {
		ajaxRequest('/restaurant/'+id_link+'/'+id+'/', '');
	}else{
		id_prev=0;
		id_curr=0;
		id_next=1;
		$('a.pr-prev').addClass('pr-prev-disabled');
		$('a.pr-next').removeClass('pr-next-disabled');
	}*/
	
}

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;
}


function mnuOver(id){
	jQuery('#mnu_'+id).attr('src',objOverMenuImageArray[id].src);
}

function mnuOut(id){
	jQuery('#mnu_'+id).attr('src',objOnMenuImageArray[id].src);
}


	
function doLoad() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		//map.setCenter(centerPoint, 10);
		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.openInfoWindowHtml(
			'<div style="width:150px;">' + title+  '</div>',{maxWidth:100});
		});
		return marker;
	}
	
	
function changeMainImage(){
	if (iTimer) {
		clearTimeout(iTimer);
		iTimer = 0;
	}
	
	++id_curr;
	
	if (id_curr==num_photos) id_curr = 0;
	
	objImagePreloader.onload = function() {
		$('#main_img_bg').css('background','url('+imgsArr[id_curr]+')');
		$('#main_img').animate({ opacity: '0' }, 400, function(){
			//$('#main_img').hide();
			$('#main_img').attr('src',imgsArr[id_curr]);
			$('#main_img').animate({ opacity: '1' }, 10, function(){
				//$('#main_img').show();
			});
		});
		
		objImagePreloader.onload=function(){};
		iTimer = setTimeout("changeMainImage()", gal_delay);
	}
		
	objImagePreloader.src = imgsArr[id_curr];
	
}	

	
jQuery (document).ready(function(){
	$('.media_block').media();
	jQuery.ifixpng('/images/pixel.gif');
	jQuery('img[src$=.png], .bgPng').ifixpng();
	jQuery('a.work_box').lightBox();
	jQuery('.ttip').tooltip({ 
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		fade: 250 
	});
	
	$("a.inline").fancybox({ 'hideOnContentClick': true }); 
		
	jQuery('.accordion .head').click(function() {
			window.location = $(this).prev().attr('href');
			/*$(this).next().slideToggle('slow', function(e){
				//if ($(this).prev().attr('rel')=='cat') window.location = $(this).prev().attr('href');
				window.location = $(this).prev().attr('href');
			});
			return false;*/
			
		}).next().not('.curr').not('.sub_info_c_li ul').hide();

		
});
	