var filterLoading = false;
var coords;
var map = new Array();
var marker = new Array();
function initFiltres(){
	$('.filter > li > h3 > a').click(function(){
		var filterId = $(this).parent().parent().parent().attr('id');
		$('#'+filterId+' > li').removeClass('active');
		$(this).parent().parent().addClass('active');
		return false;
	});
	
	$('.filter > li > ul > li > a').click(function(){
		if(!filterLoading){
			filterLoading = true;
			var parentList = $(this).parent().parent();
			parentList.children('li').children('a').removeClass('active');
			var thisId = $(this).attr('id');
			$(this).addClass('loading');
			_tempProcessData($(this).attr('href'));
			setTimeout(function(){
				filterLoading = false;
				$('#'+thisId).removeClass('loading').addClass('active');
			},1500);
		}
		return true;
	});
}


function _tempProcessData(par1){
	//alert(par1);
	return true;
}

function initGallery(id) {
	$('#' + id + ' .icons-list a').click(function () {
		$('#' + id + ' .img img').attr('src', $(this).attr('href'));
		return false;
	});
}

function initMapShops() {
	var pathMap = "/Uploads/map/";
	$('#map-regions area').click(function () {
		var reg = $(this).attr('href').replace("#map-", "");
		$('#list-shops .item-shop').removeClass('active');
		$('#list-shops #inf-map-' + reg).addClass('active');
		if ($('#inf-map-' + reg).size()){
			$.scrollTo('#list-shops #inf-map-' + reg, 300);
			$('#list-shops #inf-map-' + reg + ' .compay-photos img').each(function(i){
				$(this).attr('src',$(this).attr('lowsrc'));
			});
			$('#map-active').attr('src', pathMap + reg + '.gif');
			for(i = 0; i < coords.length; i++){
				if(coords[i].reg == reg){
					for(j=0;j < coords[i].cities.length; j++){
						if(!$('#canvas-map-'+coords[i].cities[j].city.id).text()){
							initGMap('canvas-map-'+coords[i].cities[j].city.id,coords[i].cities[j].city.lat,coords[i].cities[j].city.lng);
						}
					}
					break;
				}
			}
		}
	});
	initprettyPhoto();
}

function initprettyPhoto(){
	//var divs = new Array("ab-1", "ag-1", "ar-1", "bc-1", "bh-1", "bn-1", "br-1", "bt-1", "bv-1", "cj-1", "cj-2", "cs-1", "ct-1", "dj-1", "gj-1", "gl-1", "hd-1", "if-1", "if-2", "is-1", "mm-1", "ms-1", "ph-1", "sb-1", "sj-1", "sm-1", "sv-1", "tm-1", "vl-1", "vn-1");
	var strIDs = "";
	for (i = 0; i < divs.length; i++) {
		strIDs += "#gallery-" + divs[i] + " a[rel^='prettyPhoto']";
		if (i < (divs.length - 1)) strIDs += ", ";
	}
	$(strIDs).prettyPhoto();
}

function initGMap(id,lat,lng){
  if (GBrowserIsCompatible()){
		var center = new GLatLng(lat,lng);
		map["'"+id+"'"] = new GMap2(document.getElementById(id));
		map["'"+id+"'"].setMapType(G_MAPMAKER_NORMAL_MAP);
		map["'"+id+"'"].setCenter(center, 15);
		map["'"+id+"'"].setUIToDefault();
		marker["'"+id+"'"] = new GMarker(center);
		map["'"+id+"'"].addOverlay(marker["'"+id+"'"]);
  }
}



function insertVideo(){
	var flashvars = {};
	flashvars.image="Resources/Flash/video.jpg";
	flashvars.file="video.mp4";
	flashvars.repeat="none";
	flashvars.controlbar="none";
//	flashvars.autostart=true;
	flashvars.displayclick=true;
	flashvars.icons=false;
	flashvars.stretching="fill";
	flashvars.volume=70;
	flashvars.screencolor="F6F3ED";
	var params = {menu:false,wmode:"transparent"};
	var attributes = {id: "video-1", name: "video-1"};
	swfobject.embedSWF("Resources/Flash/player.swf", "player", "624", "397", "9.0.0","Resources/Flash/expressInstall.swf", flashvars, params, attributes);
}
var video;
function playerReady(obj) {
	if(obj['id']=='video-1'){
		video = document.getElementById(obj['id']);
		loadVideoState();
		addListeners();
		initVideoControl();
	}
};

var videoState = 'PAUSED';
var videoTime = 0;
var loadedVideoState;
var loadedVideoTime;
function saveVideoState(){
	$.cookie('videoState', videoState,{expires:14, path: '/'});
	$.cookie('videoTime', videoTime,{expires:14, path: '/'});
	if(videoState=='PLAYING'){
		video.sendEvent('PLAY');
	}
}
function loadVideoState(){
	loadedVideoState = $.cookie('videoState');
	loadedVideoTime = $.cookie('videoTime');
	if(loadedVideoState || loadedVideoTime){
		if((loadedVideoState!='PAUSED')&&(loadedVideoState!='COMPLETED')){
			video.sendEvent('VOLUME', 5);
			setTimeout("delayPlay()",200);
			//setTimeout("video.sendEvent('VOLUME', 70)",200);
			
		}
	}
	if(!$.cookie('videoState')){
		//video.sendEvent('PLAY');
		setTimeout("video.sendEvent('PLAY')",200);
	}
}
function delayPlay(){
			video.sendEvent('PLAY');
			setTimeout("video.sendEvent('SEEK', parseInt(loadedVideoTime));video.sendEvent('VOLUME', 70)",500);
}

function initVideoControl(){
	$('#video-control').click(function(){
		video.sendEvent('PLAY');
	});
}

function addListeners() {
	if (video) { 
		video.addModelListener("STATE", "stateListener");
		video.addModelListener("TIME", "positionListener");
	} else {
		setTimeout("addListeners()",100);
	}
}

function positionListener(obj) { 
	videoTime = obj.position; 
	//var st = $("#time");
	if (st) { st.text(videoTime); }
}

function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
	videoState = obj.newstate; 
	var st = $("#state");
	if (st) { st.text(videoState); }
	if(videoState=='PLAYING'){
		$('#video-control').attr('class','video-1');
	}
	else if(videoState!='PLAYING'){
		$('#video-control').attr('class','video-0');		
	}
	if(videoState=='COMPLETED'){
		$('#video-control').attr('class','video-0');		
	}
}






