/**
 * Flow Framework frontend javascript.
 * 
 * @category Flow Framework
 * @package Frontend
 * @subpackage JavaScript
 * @author Marius Podvoiskis <marius.podvoiskis@gmail.com>
 * @copyright Copyright (c) 2010, Marius Podvoiskis
 * @version Flow Framework 3.0, 2010-09-25 13:59:00
 */

/**
 * Search
 */
$(document).ready(function() {
//	$('#searchboxx').keypress(function(event) {
//		if (event.which == '13') {
//			location.href='paieska/?q=' + encodeURIComponent($(this).val());
//		}
//	});
//	
//	$('#searchboxx_img').click(function(event) {
//		location.href='paieska/?q=' + encodeURIComponent($('#searchboxx').val());
//	});
	
	$("a[rel^='lightbox']").lightBox();

});

function change_image(key) {
	$('.limages').addClass('dn');
	$('#image_' + key).removeClass('dn');
	$('.small_images img').removeClass('selected');
	$('#img_' + key).addClass('selected');
}

function set_image(src, link, key) {
	$('#main_img').attr('src', src);
	$('#main_img').parent().attr('href', link);
	$('.small_images img').removeClass('selected');
	$('#img_' + key).addClass('selected');
}

/**
 * Open popup
 */
function open_popup(name) {
	var h = $('body').height();
	$("#fade").css({ height: h + 'px', background: '#FFFFFF', opacity: 0.5 });
	$("#fade").fadeIn(300);
	$('.popup').addClass('dn');
	$('#' + name).removeClass('dn');
}

/**
 * Close popup
 */
function close_popup() {
	$("#fade").fadeOut(300);
	$('.popup').addClass('dn');
}

/**
 * Init google map for popup
 */
function init_map(id, lat, lng, content) {
	// open popup
	open_popup('map_popup_' + id);
	
	// set to center
	var popup_w = $("#map_" + id).width();
	var popup_h = $("#map_" + id).height();
	var LeftPosition = (screen.width) ? ($('body').width() - popup_w) / 2 : 0;
	var TopPosition = (screen.height) ? (screen.height - popup_h) / 2 : 0;
	TopPosition = TopPosition - 150;
	$('#map_popup_' + id).css({ marginLeft: LeftPosition + 'px', marginTop: TopPosition + 'px' });
	
	// init map
	var myLatlng = new google.maps.LatLng(lat,lng);
	var myOptions = {
	  zoom: 13,
	  center: myLatlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	}

	var map = new google.maps.Map(document.getElementById("map_" + id), myOptions);

	var contentString = content;

	var infowindow = new google.maps.InfoWindow({
	    content: contentString
	});

	var marker = new google.maps.Marker({
	    position: myLatlng,
	    map: map,
	    title:content
	});
	
	infowindow.open(map,marker);
}

/**
 * Do user action (login, logout)
 * 
 * @param string
 *            action
 * @return void
 */
function userAction(action) {
	document.user_form.user_action.value = action;
	document.user_form.submit();
}

function submit_form() {
	document.my_form.submit();
}

/**
 * Returns id from string (e.g. string "menu-9" returns 9)
 * 
 * @param string
 *            value
 * @param string
 *            separator
 * @return int
 */
function getIdFromString(value, separator) {
	var mas = value.split(separator);
	return mas[1];
}

/**
 * Auto center window script- Eric King (http://redrival.com/eak/index.shtml)
 * Permission granted to Dynamic Drive to feature script in archive For full
 * source, usage terms, and 100's more DHTML scripts, visit
 * http://dynamicdrive.com
 */
var win = null;
function NewWindow(mypage, myname, w, h, scroll) {
	var LeftPosition = (screen.width) ? (screen.width - w) / 2 : 0;
	var TopPosition = (screen.height) ? (screen.height - h) / 2 : 0;
	settings = 'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left='
			+ LeftPosition + ',scrollbars=' + scroll + ',resizable'
	win = window.open(mypage, myname, settings)
}

/**
 * Refrech session
 * 
 * @param string link
 * @return void
 */
function refresh_session(link) {
	var frame = document.getElementById("session");
	frame.src=link;
	// setTimeout("refresh_session('"+link+"')",1000*5*1); // 5 sec
	setTimeout("refresh_session('"+link+"')",1000*60*1); // 5 min
}

// end of file
