/* highslide settings*/
hs.showCredits = false;
hs.graphicsDir = '../highslide/graphics/';


/* load shoppingcart contents */
window.addEvent('load',function(){
	$('div_handlevogn_inner').load('box_handlevogn_ajax.php');
});
	
/* add product to shoppingcart */
function sendRequest(id, ant, name, price, image) {

	var elem = $('div_handlevogn_inner');
	elem.set('load', {evalScripts: true, noCache: true, method: 'post', data: 'prodid='+ id +'&antall='+ ant});
	elem.load('box_handlevogn_ajax.php');
	
	var winsize = window.getSize();
	var winscroll = window.getScroll();
	var vertpos = (winsize.y/ 2) + winscroll.y;
	$('popup_prodname').set('html',name);
	$('popup_price').set('html',price);
	$('popupimg').set('src','crop.php?source='+image+'&width=264&height=207&quality=100&position=center');
	$('popup').setStyles({'display':'block','left':((winsize.x / 2)-330) +'px','top':((vertpos)-150) +'px'});
	showGrayout(9999);
	
}

function closePopup(){
	$('popup').setStyle('display','none');
	hideGrayout();
}

/* delete product from shoppingcart */
function fjern(id) {
	
	var elem = $('div_handlevogn_inner');
	elem.set('load', {evalScripts: false, noCache: true, method: 'post', data: 'cid='+ id});
	elem.load('box_handlevogn_ajax.php');

}
	
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

//hide cart
function hideCart(){
	$('div_handlevogn').setStyle('display','none');
	$('cart_count').setStyle('color','#eeeeee');
	$('cart_count').setStyle('text-shadow','#000 2px 1px 1px');
	$('cart_count').setStyle('background-image','none');
}

function showCart(){
	$("div_handlevogn").setStyle('display','block');
	$('cart_count').setStyle('color','#666666');
	$('cart_count').setStyle('text-shadow','none');
	$('cart_count').setStyle('background-image',"url('../images/cartcount_bg.png')");
	
}

//delay searchbox hide
function delayHideCart(){
	cartPopupTO=setTimeout("hideCart()",900);
}

//clear searchbox hide delay
function clearHideCart(){
	if (typeof cartPopupTO!='undefined'){
		clearTimeout(cartPopupTO);
	}
}

function showGrayout(zindex){
	var winsize = window.getScrollSize();
	$('grayout').setStyle('display','block');
	$('grayout').set('opacity','0');
	$('grayout').tween('opacity','0.4');
	$('grayout').setStyles({'width':winsize.x+'px','height':winsize.y+'px','z-index':zindex})
	
}

function hideGrayout(){
	$('grayout').tween('opacity',0).setStyle('display','none');
}

window.addEvent('domready',function(){
	
	/* searchbox search */
	$('searchfield').addEvents({
		'keyup': function(e){
			if($('searchfield').value.length >=2 ){
				//clear timeout, if it was set
				if (typeof searchQueryTO!="undefined"){
					clearTimeout(searchQueryTO);
				}
				e.stop();
				//start timeout for query
				searchQueryTO=setTimeout("searchItems($('searchfield'))", 400);
			}else{
	
				if (typeof searchQueryTO!="undefined"){
					clearTimeout(searchQueryTO);
				}
				$('search_result_container').setStyle('display','none');
				$('search_result_inner').innerHTML = "";
			}
		}
		
	}).setProperty("autocomplete", "off");
	
	$('search_result_container').addEvents({
		'mouseover': function(){
			clearHideSearch();
		},
		'mouseout': function(){
			delayHideSearch();
		}
	});
	
	/* searchbox */
	var searchFx = new Fx.Tween('searchfield', {
		duration: 400,
		transition: 'linear',
		link: 'cancel',
		property: 'width'
	});
	
	
	$('searchfield').addEvent('focus', function(event){
		event.stop();
		searchFx.start(402, 789);
	});
	
	$('searchfield').addEvent('blur', function(event){
		event.stop();
		searchFx.start(789, 402);
		//hideSearch();
	});
	
	$('cartli').addEvents({
		'mouseover': function(){
			clearHideCart()
			showCart();
		},
		'mouseout': function(){
			delayHideCart();
		}
	});
	
	
});

if ( document.images ){
img1 = new Image ( ); img1.src = "../images/kjop_hover.png";
img2 = new Image ( ); img2.src = "../images/kjop_onclick.png";
}
