function write_swf(filename,id,width,height,extra) {
	document.write('<object type="application/x-shockwave-flash" data="'+filename+(id!=null?'?cid='+id:'')+'" width="'+width+'" height="'+height+'">');
	document.write('<param name="movie" value="'+filename+(id!=null?'?cid='+id:'')+'" />');
	
	document.write('<param name="quality" value="autohigh" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="menu" value="false" />');
	

	for (i in extra) {
			document.write('<param name="'+extra[i][0]+'" value="'+extra[i][1]+'" />');
	}
	document.write('</object>');
}

// flash video player, default skin
function write_player_sound(fname,preview) {
	var so = new SWFObject('flash/player.swf', 'pvideo','320','240','8');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','false');
	so.addParam('wmode','transparent');
	so.addVariable('width','320');
	so.addVariable('height','240');
	so.addVariable('file',fname);
	so.addVariable('image',preview);
	so.addVariable('javascriptid','pvideo');
	so.addVariable('enablejs','true');
	so.addVariable('backcolor', 'cccccc');
	so.addVariable('screencolor', '000000');
	so.addVariable('skin', '');
	so.addVariable('controlbar', 'over');
	so.addVariable('mute', 'false');
	so.addVariable('autostart', 'false');
	so.write('player');
}

/*
* PROTOTYPES for IE and other older browsers
*/
// in array function
function inArray(needle, haystack) {
	for (h in haystack) {
		if (haystack[h] == needle) {
			return true;
		}
	}
	return false;
}
// indexOf function
if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function(elt /*, from*/) {
    var len = this.length;
    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++) {
      if (from in this && this[from] === elt)
	  return from;
    }
    return -1;
  };
} 

/* toggle font / line size */
/* set cookie */
//function setCookie(name, value, expires, path, domain, secure) {
function setCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/* get cookie */
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

/* delete cookie */
function deleteCookie( name, path, domain ) {
	if ( getCookie(name) ) 
		document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

var text_sizes		= [12, 14, 16];
var line_heights	= [1.4, 1.6, 1.8];

var def_text_size = 0;
var def_line_height = 0;

var current_lh = false;
var current_ts = false;

var first_page = false;

var content_placeholder = 'middleblock';

function change_line_height() {

	if (!current_lh)
	current_lh = getCookie('line_height');

	if (!current_lh) current_lh = def_line_height;
	current_lh ++;
	if (current_lh == line_heights.length) current_lh = 0;

	setCookie('line_height', current_lh, 365);
	if (first_page) {
		document.getElementById('push_news').style.lineHeight = line_heights[current_lh] + "em";
		document.getElementById('push_strokovnjak').style.lineHeight = line_heights[current_lh] + "em";
	} else {
		document.getElementById('middleblock').style.lineHeight = line_heights[current_lh] + "em";
	}
}

function change_text_size() {
	if (!current_ts)
		current_ts = getCookie('text_size');
	if (!current_ts) current_ts = def_text_size;
	current_ts ++;
	if (current_ts == text_sizes.length) current_ts = 0;
	setCookie('text_size', current_ts, 365);
	if (first_page) {
		document.getElementById('push_news').style.fontSize = text_sizes[current_ts] + "px";
		document.getElementById('push_strokovnjak').style.fontSize = text_sizes[current_ts] + "px";
	} else {
		document.getElementById('middleblock').style.fontSize = text_sizes[current_ts] + "px";
	}
}

/* returns the x,y coordinates of the current screen (for multi monitor setup) */
function get_top_left(width, height){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
	  		winW = window.innerWidth;
	  		winH = window.innerHeight;
	 		winL = window.screenX;
	 		winT = window.screenY;
	 	} else {
	  		winW = document.body.offsetWidth;
	  		winH = document.body.offsetHeight;
	  		winL = window.screenLeft;
	  		winT = window.screenTop;
	 	}
	}
	
	var scroll = 0;
	var l = winL + winW/2 - width/2;
	var t = winT + winH/2 - height/2;
	
	
  	if(screen.width <= width){
  		width=screen.width;
  	}
  	if(screen.height <= height){
  		height=screen.height;
 	 	var t = 0;
  		var scroll = 1;
  	}
	return Array(t,l);
}


/* generic window opener */
function openwin(uri,title,w,h){
	if(w){wwidth = w;}else{	wwidth = 380;}
	if(h){wheight = h; }else{ wheight = 380;}
	xy = get_top_left(wwidth, wheight);
	wleft = xy[1];
	wtop = xy[0];
	wnd = window.open(uri, title, "width="+wwidth+", height="+wheight+", left="+wleft+", top="+wtop+", toolbar=no, location=no, scrollbars=yes, status=no, menubar=no, resizable=no, directories=no");
}

/************************************************************//***********************************************************************/

var xPos = 0;
var speed = 5;

var intLeft;
var intRight;

function slide_left() {
	clearInterval(intRight);
	intLeft = setInterval("go_left()", 10);
}

function slide_right() {
	clearInterval(intLeft);
	intRight = setInterval("go_right()", 10);
}

function go_left() {
	
	var slideWidth = $('#slide').width();
	
	if (xPos < 0) {
		/*
		if (document.getElementById('gal_left_link').style.display == 'none') {
			document.getElementById('gal_left_link').style.display = 'block';
		}*/
	}
	
	if (xPos > (580 - slideWidth)) {
		xPos = xPos-speed;
		document.getElementById('slide').style.left = xPos+'px';
	} else {
		
		/*
		if (document.getElementById('gal_right_link').style.display == 'block') {
			document.getElementById('gal_right_link').style.display = 'none';
		}*/
	}
}

function go_right() {
	
	
	if (xPos < 0) {
		/*
		if (document.getElementById('gal_right_link').style.display == 'none') {
			document.getElementById('gal_right_link').style.display = 'block';
		}
		*/
		
		xPos = xPos+speed;
		document.getElementById('slide').style.left = xPos+'px';
	} else {
	
		
		/*
		if (document.getElementById('gal_left_link').style.display == 'block') {
			document.getElementById('gal_left_link').style.display = 'none';
		}
		*/
	}
}

function stop_slide() {
	clearInterval(intLeft);
	clearInterval(intRight);
}

$(document).ready(function(){
	
	//$('.slidebutton').css('display','none');
	$('.slide .slidebutton').css('display','block');
	
	$(".slide .btn-slide-l").mousedown(function(){
		stop_slide();
		slide_right();
		
		$('.slidebutton').removeClass('pressed');
		$(this).addClass('pressed');
		
		return false;
	});
	

	$(".slide .btn-slide-r").mousedown(function(){
		stop_slide();
		slide_left();
		
		$('.slidebutton').removeClass('pressed');
		$(this).addClass('pressed');
		
		return false;
	});
	
	$('.slide .slidebutton').click(function(){
		$('.slidebutton').removeClass('pressed');
		return false;
	});
	$('.slide .slidebutton').mouseup(function(){
		$('.slidebutton').removeClass('pressed');
		stop_slide();
		return false;
	});
	$('.slide .slidebutton').mouseout(function(){
		$('.slidebutton').removeClass('pressed');
		stop_slide();
		return false;
	});
	
	
	$('#slide a.unselected img').css('opacity','0.30');
	$('#slide a.selected img').css('opacity','1');
	
	
	$('#slide a.unselected').hover(
		function() {
			$('img',this).css('opacity','1');
			$('#catalogue_bottom').html($('img',this).attr('alt'));
		},function() {
			$('img',this).css('opacity','0.30');
			$('#catalogue_bottom').html('');
	});
	
	$('.packing_select').click(function(){
		$('.img_detail').css('display','none');
		$('#image'+$(this).attr('rel')).css('display','inline');
		return false;
	});
	
	var xReposition;
	if($('#catalogue_wrap').hasClass('slide')) {
		xReposition = -((parseInt($('#slide .selected').attr('rel'))-1) * 80);
	} else {
		xReposition = 'default';
	}
	
	if (!(isNaN(xReposition))) {
		xPos = xReposition;
		//document.getElementById('slide').style.left = xReposition+'px';
		$('#slide').animate({
			left : xReposition+'px'
		},500);
	}
	
	
	$('html').click(function(){
		if(parseInt($('#lang').css('height')) > 20) {
			$('#lang').css('height','20px');
		}
	});
	$('#lang span a').click(function(e){
		var height_factor = $('div','.wrapman').size();
		var height_element = $('div','.wrapman').height();
		dropdown_height = parseInt(height_factor*height_element) + 22;
		
		
		$('#lang').css('height',dropdown_height+'px');
		e.stopPropagation();
		return false;
	});
	$('#lang a').click(function(e){
		$('#lang span a.showman').focus();
	});
	$('#lang div a').click(function(e){
		$('#lang span a.showman').focus();
		$('#lang span a.showman').html($(this).html());
	});
	$('#lang a.arrow').mousedown(function(){
		$(this).css('background-position','right bottom');
	});
	$(document).mouseup(function(){
		$('#lang a.arrow').css('background-position','right top');
	});
	
});
/************************************************************//***********************************************************************/

