try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}
var defaultInputValues = new Array();
var fb_opt = {'overlayShow': true, 'overlayOpacity': 0.70, 'zoomSpeedIn' : 300, 'zoomSpeedOut' : 400};

$(function() {
	// image preload
	$.preloadImages(_appRoot + "/images/background/submenu-hover.png", _appRoot + "/images/loader.gif");
	
	// png fix for ie6
	$('#banner-container, #menu, #right, h1, a.image').supersleight({shim: _appRoot+'/images/blank.gif'});
	
	// auto clear input fields
	$(".autoClear").each(function(index){
		defaultInputValues[index] = $(this).val();
		$(this).focus(function() { if ($(this).val() == defaultInputValues[index]) { $(this).val('') } }).blur(function(){if ($(this).val()=='') {$(this).val(defaultInputValues[index])}})});
	
	// form submition
	$("#contacts a.submit").click(function(){$(this).closest("form").submit(); return false;});
	
	// fancybox init
	if ($.isFunction($.fn.fancybox)) {
		$("a.main, .partners a.image").fancybox(fb_opt);
	}
	
	// jscrollpane init
	$('#featured, #content').jScrollPane({showArrows:true});

	// gallery
	if (isDefined("objectId")) {
		galleryInit();
	}
});

function galleryInit() {
	galleryLoad(objectId, type, 1);
	$("#gallery .nav a").live("click", galleryChangePage);
}
function galleryLoad(id, type, page) {
	$("#gallery ul").remove();
	$("#gallery .loader").show();
	$.post(_appRoot+'/'+_lang+'/ajax/image.php', {method:'get',id:id,p:page,t:type} , function(data){ 
		$("#gallery ul").remove();
		$("#gallery .loader").hide();
		$("#gallery .nav").html(data.nav).supersleight({shim: _appRoot+'/images/blank.gif'});
		if (data.items.length > 0) {
			$("#gallery .container").append($("<ul>"));
			$.each(data.items, function(i,item){
				$("#gallery ul").append($("<li>").html(item));
			});
			$("#gallery ul").show("fast");
			$("#gallery ul a").fancybox(fb_opt);
		} else {
			$("#gallery").hide();
		}
	}, "json");
}
function galleryChangePage() {
	var page = $(this).attr('rel');
	galleryLoad(objectId, type, page);
}
jQuery.preloadImages = function() {
  for(var i = 0; i<arguments.length; i++) {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
function isDefined(variable) {
	return (typeof(window[variable]) == 'undefined') ? false : true;
}
