//
// jResizer 2.0
// unobtrusive resizing of font sizes and line heights
// vm @ Sonce.net
//
// Change only config options here
//

var ContentBoxId = 'content'; // ID elementa z vsebino
var FontResizeButton = 't-fontsize'; // ID gumba za povecavo teksta
var LineHeightButton = 't-lineheight'; // ID gumba za povecavo razmaka med vrsticami
var PrintButton = 't-print'; // ID gumba za tiskanje
var FontCssSizeUnits = 'px'; // Enota za velikost pisave (px ali em)
var LineCssSizeUnits = 'em'; // Enota za razmak vrstic (px ali em)
var UniqueCookieName = 'perovo'; // Unikatno ime za piskotke tega site-a
var AllFontSizes = Array(13, 15, 17); // Seznam velikosti pisav - prva se nastavi sama
var AllLineHeights = Array(1.38, 1.69, 2.0); // Seznam razmakov vrstic - prva se nastavi sama

//
// jQuery Cookie implementation
//

jQuery.cookie = function(name, value, options) {
 if (typeof value != 'undefined') { // name and value given, set cookie
 options = options || {};
 if (value === null) {
 value = '';
 options.expires = -1;
 }
 var expires = '';
 if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
 var date;
 if (typeof options.expires == 'number') {
 date = new Date();
 date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
 } else {
 date = options.expires;
 }
 expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
 }
 // CAUTION: Needed to parenthesize options.path and options.domain
 // in the following expressions, otherwise they evaluate to undefined
 // in the packed version for some reason...
 var path = options.path ? '; path=' + (options.path) : '';
 var domain = options.domain ? '; domain=' + (options.domain) : '';
 var secure = options.secure ? '; secure' : '';
 document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
 } else { // only name given, get cookie
 var cookieValue = null;
 if (document.cookie && document.cookie != '') {
 var cookies = document.cookie.split(';');
 for (var i = 0; i < cookies.length; i++) {
 var cookie = jQuery.trim(cookies[i]);
 // Does this cookie string begin with the name we want?
 if (cookie.substring(0, name.length + 1) == (name + '=')) {
 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
 break;
 }
 }
 }
 return cookieValue;
 }
};

//
// Array Prototype implementation
//

Array.prototype.indexOf = function(a) {
 for (var i in this) {
 if (this[i]==a) {
 return i;
 }
 } 
 return false;
}

//
// Text resizing and line height functions
//

$(document).ready(function(){

 // Font resize
 if($.cookie('fontsize_' + UniqueCookieName) == null) {
 $.cookie('fontsize_' + UniqueCookieName, AllFontSizes[0], { expires: 7, path: '/', domain: '', secure: false });
 $('#' + ContentBoxId).css({
 'font-size': AllFontSizes[0] + FontCssSizeUnits
 });
 } else {
 $('#' + ContentBoxId).css({
 'font-size': $.cookie('fontsize_' + UniqueCookieName) + FontCssSizeUnits
 });
 }
 
 $('#' + FontResizeButton).click(function(){
 var CurrentFontSize = parseFloat(AllFontSizes.indexOf($.cookie('fontsize_' + UniqueCookieName))) + parseFloat(1);
 if(CurrentFontSize == AllFontSizes.length) {
 NewFontSize = AllFontSizes[0];
 } else {
 NewFontSize = AllFontSizes[CurrentFontSize];
 }
 $.cookie('fontsize_' + UniqueCookieName, NewFontSize, { expires: 7, path: '/', domain: '', secure: false });
 $('#' + ContentBoxId).css({
 'font-size': NewFontSize + FontCssSizeUnits
 });
 return false;
 });
 
 // Change line height
 if($.cookie('lineheight_' + UniqueCookieName) == null) {
 $.cookie('lineheight_' + UniqueCookieName, AllLineHeights[0], { expires: 7, path: '/', domain: '', secure: false });
 $('#' + ContentBoxId).css({
 'line-height': AllLineHeights[0] + LineCssSizeUnits
 });
 } else {
 $('#' + ContentBoxId).css({
 'line-height': $.cookie('lineheight_' + UniqueCookieName) + LineCssSizeUnits
 });
 }
 
 $('#' + LineHeightButton).click(function(){
 var CurrentLineHeight = parseFloat(AllLineHeights.indexOf($.cookie('lineheight_' + UniqueCookieName))) + parseFloat(1);
 if(CurrentLineHeight == AllLineHeights.length) {
 NewLineHeight = AllLineHeights[0];
 } else {
 NewLineHeight = AllLineHeights[CurrentLineHeight];
 }
 $.cookie('lineheight_' + UniqueCookieName, NewLineHeight, { expires: 7, path: '/', domain: '', secure: false });
 $('#' + ContentBoxId).css({
 'line-height': NewLineHeight + LineCssSizeUnits
 });
 return false;
 });

 // Print
 $('#' + PrintButton).click(function(){
 print();
 return false;
 });

});
/* Copyright (c) 2007 Paul Bakaus (paul.bakaus@googlemail.com) and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-12-20 08:43:48 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4257 $
 *
 * Version: 1.2
 *
 * Requires: jQuery 1.2+
 */
(function($){$.dimensions={version:'1.2'};$.each(['Height','Width'],function(i,name){$.fn['inner'+name]=function(){if(!this[0])return;var torl=name=='Height'?'Top':'Left',borr=name=='Height'?'Bottom':'Right';return this.is(':visible')?this[0]['client'+name]:num(this,name.toLowerCase())+num(this,'padding'+torl)+num(this,'padding'+borr);};$.fn['outer'+name]=function(options){if(!this[0])return;var torl=name=='Height'?'Top':'Left',borr=name=='Height'?'Bottom':'Right';options=$.extend({margin:false},options||{});var val=this.is(':visible')?this[0]['offset'+name]:num(this,name.toLowerCase())+num(this,'border'+torl+'Width')+num(this,'border'+borr+'Width')+num(this,'padding'+torl)+num(this,'padding'+borr);return val+(options.margin?(num(this,'margin'+torl)+num(this,'margin'+borr)):0);};});$.each(['Left','Top'],function(i,name){$.fn['scroll'+name]=function(val){if(!this[0])return;return val!=undefined?this.each(function(){this==window||this==document?window.scrollTo(name=='Left'?val:$(window)['scrollLeft'](),name=='Top'?val:$(window)['scrollTop']()):this['scroll'+name]=val;}):this[0]==window||this[0]==document?self[(name=='Left'?'pageXOffset':'pageYOffset')]||$.boxModel&&document.documentElement['scroll'+name]||document.body['scroll'+name]:this[0]['scroll'+name];};});$.fn.extend({position:function(){var left=0,top=0,elem=this[0],offset,parentOffset,offsetParent,results;if(elem){offsetParent=this.offsetParent();offset=this.offset();parentOffset=offsetParent.offset();offset.top-=num(elem,'marginTop');offset.left-=num(elem,'marginLeft');parentOffset.top+=num(offsetParent,'borderTopWidth');parentOffset.left+=num(offsetParent,'borderLeftWidth');results={top:offset.top-parentOffset.top,left:offset.left-parentOffset.left};}return results;},offsetParent:function(){var offsetParent=this[0].offsetParent;while(offsetParent&&(!/^body|html$/i.test(offsetParent.tagName)&&$.css(offsetParent,'position')=='static'))offsetParent=offsetParent.offsetParent;return $(offsetParent);}});function num(el,prop){return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0;};})(jQuery);
// DONE: image description rollover
// DONE: thumbnail gallery
// DONE: IE Naviagtion fix
// DONE: window.onresize element reposition
// TODO: window scroll - gallery must be centered

/**
 * Generic popover gallery
 */
(function($) {

 // defautl configuration
 var default_config = {
 opacity: 0.8, // overlay opacity
 data_source: '', // data script url or false for inline gallery
 
 slideshow_enabled: true, // do we have a slideshow toggle button?
 slideshow_speed: 5, // no. seconds between transitions
 slideshow_auto_start: false, // no. seconds between transitions
 
 thumbnail_preview: true, // do we have thumbnail preview?
 
 mode: 'gallery' // gallery mode - "single" image or "gallery" image
 }
 
 // actual merged configuration
 var config = Array();
 
 
 var collection = Array(); // collection of images
 var current_index = 0; // current image index
 var slideshow_interval = false; // slideshow interval handler
 
 var gallery_counter = -1;
 var current_gallery = 0;
 /**
 * constructor
 */
 $.fn.popover_gallery = function(options) {
 
 
 gallery_counter++;
 current_gallery = gallery_counter;
 config[current_gallery] = $.extend({}, default_config, options);
 
 if (typeof config[current_gallery].placeholder == "string") config_array[current_gallery].placeholder = $(config_array[current_gallery].placeholder);
 
 // build the image dataset
 
 build_dataset();
 $(window).resize(function() {
 $.fn.popover_gallery.reposition();
 });
 
 return this.each(function() {
 
 // find all links that are wrapped around an image in the placeholder element
 $(this).find("a.generic").each(function(i) {
 var temp = current_gallery;
 $(this).bind('click', function(event) {
 
 event.preventDefault();
 if (this.rel == '') {
 current_index = i;
 } else {
 current_index = parseInt(this.rel)-1;
 }
 
 $.fn.popover_gallery.open(temp);
 this.blur();
 });
 });
 }); 
 
 }
 
 /**
 * opens the popover galery 
 */
 $.fn.popover_gallery.open = function (gallery_index) {
 
 current_gallery = gallery_index;
 
 // hide object and embed
 $('object, embed').each(function() {
 
 if ($(this).css('visibility') != 'hidden') {
 $(this).data('popover_gallery', { hidden: true});
 $(this).css('visibility', 'hidden');
 }

 });
 
 
 try {
 
 // init objects and properties
 init();
 
 // opening sequence
 $("#pg_overlay").fadeIn('normal', function() {
 $("#pg_toolbox").slideDown('normal', function() {
 return;
 });
 });
 
 // attach the close event on the overlay
 $("#pg_overlay").bind('click', $.fn.popover_gallery.close);
 $("#pg_close").click($.fn.popover_gallery.close);
 
 $('#pg_loading').attr('className', 'black');

 show_image();
 
 if (config.slideshow_auto_start) {
 $.fn.popover_gallery.start_slideshow(true);
 }
 
 } catch (e) {
 // do nothing 
 return false;
 }
 }
 
 /**
 * creates all the elements needed for the UI
 */
 function init() {
 // creating transparent overlay
 if (typeof($('#pg_overlay')[0]) == 'undefined') {
 var overlay = '<div id="pg_overlay"></div>';
 $("body").append(overlay);
 
 // applying style
 $("#pg_overlay").css({
 opacity: config[current_gallery].opacity
 });
 }
 
 show_loader();
 
 // creating the toolbox
 if (typeof($('#pg_toolbox')[0]) == 'undefined') {

 var toolbox = '<div id="pg_toolbox"></div>';
 
 $("body").append(toolbox);
 
 var append_str = '<a id="pg_close" href="#"><span>Close</span></a>';
 
 if (config[current_gallery].slideshow_enabled == true && collection[current_gallery].length > 1) {
 append_str += '<div id="pg_slide">';
 append_str += '<a id="pg_play" href="#"><span>Play</span></a>';
 append_str += '<a id="pg_minus" href="#"><span>-</span></a>';
 append_str += '<span id="pg_speed">' + config[current_gallery].slideshow_speed + 's</span>';
 append_str += '<a id="pg_plus" href="#"><span>+</span></a>';
 append_str += '</div>';
 }
 
 append_str += '<div id="pg_nav">';
 if (collection[current_gallery].length > 1) {
 append_str += '<a href="#" id="pg_prev"><span> << </span></a>';
 append_str += '<a href="#" id="pg_next"><span> >> </span></a>';
 }
 append_str += '<span id="pg_index">0/0</span>';
 if (collection[current_gallery].length > 1)
 
 append_str += '</div>';
 
 $("#pg_toolbox").append(append_str);
 
 $('#pg_next').click($.fn.popover_gallery.next);
 $('#pg_prev').click($.fn.popover_gallery.prev);
 
 if (config[current_gallery].slideshow_enabled) {
 $('#pg_play').click($.fn.popover_gallery.start_slideshow);
 $('#pg_minus').click($.fn.popover_gallery.speed_down);
 $('#pg_plus').click($.fn.popover_gallery.speed_up);
 }
 
 if (config[current_gallery].thumbnail_preview && collection[current_gallery].length > 1) {
 
 $("#pg_nav").append('<div id="pg_show_thumbs"></div>');
 $("#pg_toolbox").append('<div id="pg_thumbnails"><span></span></div>');
 
 last_in_row = 10;
 if (collection[current_gallery].length>54) {
 $("#pg_thumbnails").addClass('scrollable');
 last_in_row = 9;
 }
 
 if ($.browser.msie) {
 $("#pg_thumbnails").css({ borderBottom: '1px solid'});
 }
 
 // open thumbnails list
 $("#pg_show_thumbs").mouseover(function() {
 $('#pg_thumbnails').slideDown(400);
 return false;
 });
 
 
 var pg_timer_out;
 
 // close thumbnails lisr
 $("#pg_thumbnails").mouseout(function() {
 pg_timer_out = setTimeout(function() {
 $('#pg_thumbnails').slideUp(400);
 }, 400);
 });
 
 $("#pg_thumbnails").mouseover(function() {
 clearTimeout(pg_timer_out);
 });
 
 }
 
 
 
 }
 
 $('#pg_thumbnails').empty();

 var append_string= '';
 for (i=0; i<collection[current_gallery].length;i++) {
 append_string += '<div></div>';
 }
 
 $('#pg_thumbnails').append(append_string);
 
 counter = 0;
 
 $('#pg_thumbnails div').each(function(i) {
 
 counter++;
 if ( i!=0 && counter % last_in_row == 0) {
 counter=0;
 $(this).css({marginRight: -2});
 }
 
 
 $(this).css({
 display: 'block',
 background: 'transparent url('+collection[current_gallery][i].thumbnail+') center center no-repeat',
 width: 55,
 height: 55
 })
 
 $(this).src = '';
 
 $(this).click(function() {
 $.fn.popover_gallery.set_index(i);
 });
 });
 
 if (typeof($('#pg_frame')[0]) == 'undefined') {
 content_placeholder = '<div id="pg_frame"><div id="pg_content"><img src="" alt="" title=""></img><div id="pg_desc"></div><div id="pg_desc_text"></div><div id="pg_info"></div></div></div>';
 $('body').append(content_placeholder);
 }
 
 $.fn.popover_gallery.reposition();
 
 $("#pg_thumbnails").css({
 left: 0,
 top: tb_height - 1,
 width: tb_width - 3
 });
 
 if (collection[current_gallery].length > 1) {
 $('#pg_content img').click($.fn.popover_gallery.next).css({
 cursor: 'pointer'
 });
 
 }
 
 }
 
 /**
 * reposition all elements (on window rezize / scroll??)
 */
 $.fn.popover_gallery.reposition = function() {
 // get document dimensions
 body_width = $(document).width();
 // Opera dirty fix
 if($.browser.opera) {
 body_width = $('body').width();
 }
 
 body_height = $(document).height();
 
 $("#pg_overlay").css({ height: body_height });
 
 tb_width = parseInt($("#pg_toolbox").outerWidth());
 tb_height = parseInt($("#pg_toolbox").outerHeight());
 tb_left = Math.round((body_width - tb_width)/2);
 tb_top = 50;
 
 // ~vm
 // Opera dirty fix
 if($.browser.opera) {
 tb_left = Math.round((body_width - 563)/2);
 tb_width = 563;
 $("#pg_thumbnails").css({
 'margin-top': 18
 });
 }
 
 // positioning the toolbox ~vm fix
 if (typeof(document.body.style.maxHeight) != "undefined") {
 tb_top_scrolled = tb_top;
 } else {
 tb_top_scrolled = tb_top + $(document).scrollTop();
 }
 
 $("#pg_toolbox").css({
 left: tb_left,
 top: tb_top_scrolled
 });
 
 frame_width = $('#pg_frame').width();
 frame_height = $('#pg_frame').height();
 
 // position: the frame
 frame_left = (body_width/2) - (frame_width/2);
 frame_top = $(document).scrollTop() + Math.round(($(window).height() - frame_height)/2);
 
 if($.browser.opera) {
 frame_top = $('body').scrollTop() + Math.round(($(window).height() - frame_height)/2);
 }
 
 $('#pg_frame').css({
 width: frame_width,
 height: frame_height,
 left: frame_left,
 top: frame_top
 });
 
 // IE 7 hack
 // Ce ni IE6, pozicioniraj fixed
 if (typeof document.body.style.maxHeight != "undefined") {
 $('#pg_frame').css({ position: 'fixed' });
 $('#pg_toolbox').css({ position: 'fixed' });
 } else {
 $(window).one('scroll', $.fn.popover_gallery.reposition);
 }

 }
 
 /**
 * closes the gallery and removes everything.
 */
 $.fn.popover_gallery.close = function(event) {
 try {
 event.preventDefault();
 clearInterval(slideshow_interval);
 } catch (e) {}
 
 
 
 $("#pg_overlay").unbind('click');
 
 $("#pg_toolbox, #pg_loading, #pg_frame, #pg_overlay").fadeOut('fast', function() {
 current_index = 0;
 });
 
 $('object, embed').each(function() {
 
 if($(this).data('popover_gallery') && $(this).data('popover_gallery').hidden === true) {
 $(this).css('visibility', 'visible');
 $(this).data('popover_gallery', {hidden: false});
 }
 });
 }
 
 /**
 * make an ajax call to the server to get the image array
 */
 function build_dataset(params) {

 // inline gallery
 if (!config[current_gallery].data_source) {
 // return false;
 } else {
 
 $.ajax({
 cache: true,
 type: 'POST',
 url: config[current_gallery].data_source,
 data: {
 popover_gallery: 1,
 size: config[current_gallery].thumbnail_size,
 gallery_index: current_gallery
 },
 dataType: 'json',
 success: function(result) {
 // server returned json array of objects
 collection[result[0].gallery_index] = result;
 },
 error: function(obj, status, error) {
 }
 });
 }
 }
 
 // starts the slideshow
 $.fn.popover_gallery.start_slideshow = function(event) { 
 try {
 event.preventDefault();
 } catch (e) {}
 
 // ui update
 $("#pg_play").blur();
 $("#pg_play").unbind('click');
 $("#pg_play").bind('click', $.fn.popover_gallery.stop_slideshow);
 $("#pg_play").addClass('started');
 
 // refresh the interval time
 if (slideshow_interval) clearInterval(slideshow_interval);
 // run slidehow
 slideshow_interval = setInterval($.fn.popover_gallery.next, config[current_gallery].slideshow_speed * 1000);
 }
 
 // show next image
 $.fn.popover_gallery.next = function(event) {
 try {
 if (this!=window) {
 this.blur();
 event.preventDefault();
 }
 } catch (e) {}
 current_index++;
 if (current_index >= collection[current_gallery].length) current_index = 0;
 show_image();
 }
 
 // show previous image
 $.fn.popover_gallery.prev = function(event) {
 try {
 event.preventDefault();
 } catch (e) {}
 
 $("#pg_minus").blur();
 
 current_index--;
 
 if (current_index < 0) current_index = collection[current_gallery].length-1;
 
 show_image();
 }
 
 // set the current image index
 $.fn.popover_gallery.set_index = function (num) {
 current_index = num;
 show_image();
 }
 
 // increase slideshow speed
 $.fn.popover_gallery.speed_up = function(event) {
 try {
 event.preventDefault();
 } catch (e) {}
 
 $("#pg_plus").blur();
 
 config[current_gallery].slideshow_speed = config[current_gallery].slideshow_speed + 1;
 if (config[current_gallery].slideshow_speed > 15) 
 config[current_gallery].slideshow_speed = 15;
 
 $('#pg_speed').html(config[current_gallery].slideshow_speed + 's');

 $.fn.popover_gallery.start_slideshow();
 }
 
 // decrease slideshow speed
 $.fn.popover_gallery.speed_down = function(event) {
 try {
 this.blur();
 event.preventDefault();
 } catch (e) {
 
 }
 
 config[current_gallery].slideshow_speed = config[current_gallery].slideshow_speed - 1;
 if (config[current_gallery].slideshow_speed < 1) 
 config[current_gallery].slideshow_speed = 1;
 
 $('#pg_speed').html(config[current_gallery].slideshow_speed + 's');
 
 $.fn.popover_gallery.start_slideshow();
 }
 
 
 
 // stops the slideshow
 $.fn.popover_gallery.stop_slideshow = function(event) {
 try {
 event.preventDefault();
 } catch (e) {}
 
 $("#pg_play").blur();
 $("#pg_play").removeClass('started');
 $("#pg_play").unbind('click');
 $("#pg_play").bind('click' ,$.fn.popover_gallery.start_slideshow);
 
 if (slideshow_interval != false) {
 clearInterval(slideshow_interval);
 slideshow_interval = false;
 }
 }
 
 /**
 * load and show the current image
 */
 function show_image() {

 if (config[current_gallery].thumbnail_preview == true) {
 $('#pg_thumbnails').slideUp(300);
 }
 
 $('#pg_content').hide();
 
 show_loader();
 
 current_image = collection[current_gallery][current_index];
 
 tmp_img = new Image();
 tmp_img.onload = function() {
 frame_width = this.width + 50;
 frame_height = this.height + 50;
 
 // position: the frame
 frame_left = ($(document).width()/2) - (frame_width/2);
 
 if($.browser.opera) {
 frame_left = ($('body').width()/2) - (frame_width/2);
 }
 
 frame_top = Math.round(($(window).height() - frame_height)/2);
 if (!(typeof document.body.style.maxHeight != "undefined")) {
 frame_top += $(document).scrollTop();
 }
 
 // we do not have the main frame visible, lets make it (first time use)
 if ($('#pg_frame').css('display') != 'block') {
 $('#pg_frame').css({
 width: frame_width,
 height: frame_height,
 left: frame_left,
 top: frame_top
 });
 } else { // frame is allready present! just resize and display the content
 $('#pg_frame').animate({
 width: frame_width,
 height: frame_height,
 left: frame_left,
 top: frame_top
 }, 500);
 }
 
 $('#pg_content img').attr('src', tmp_img.src);
 
 hide_loader();
 
 $('#pg_index').html((current_index+1) + "/" + collection[current_gallery].length);
 
 
 $('#pg_btn_info').unbind('mouseover');
 $('#pg_btn_info').unbind('mouseout');
 $('#pg_info').empty()
 if (current_image.title != '') {
 $('#pg_info').append('<span>' + current_image.title + '</span>');
 }
 
 if (current_image.description != '') {
 
 $('#pg_desc, #pg_desc_text').empty().html('<div>' + current_image.description + '</div>').css({
 position: 'absolute',
 left: -5000,
 bottom: ($.browser.msie) ? 25 : 0,
 opacity: 0.7,
 height: 'auto',
 width: this.width
 });
 
 // IE layout fix 
 if ($.browser.msie){ 
 $("#pg_info").css({bottom:0});
 }
 
 $('#pg_desc_text').css({
 opacity: 1,
 left: -5000
 });
 
 $('#pg_info').append('<a href="#" id="pg_btn_info"><span>info</span></a>');
 
 $('#pg_btn_info').click(function() {
 return false;
 });
 } else {
 // IE layout fix 
 if ($.browser.msie){ 
 $("#pg_info").css({bottom:0});
 }
 }
 
 $('#pg_frame').fadeIn('normal', function() {
 $('#pg_content').fadeIn('fast', function() {
 
 // get tje height of the desctiption box while visible
 tmp_height = $('#pg_desc').height();
 
 $('#pg_desc, #pg_desc_text').css({
 left: 25,
 height: 0,
 display: 'none'
 });
 
 // handle the mouse events on info button
 $('#pg_btn_info').hover(
 function() {
 $('#pg_desc, #pg_desc_text').css({display: 'block'})
 $('#pg_desc, #pg_desc_text').animate({
 height: tmp_height
 }, 400);
 },
 function() {
 $('#pg_desc, #pg_desc_text').animate({
 height: 0
 }, 400, function() {
 $('#pg_desc, #pg_desc_text').css({display: 'none'})
 })
 }
 );
 });
 
 });
 }
 
 tmp_img.src = current_image.picture;
 }
 
 /**
 * shows the loading animation
 */
 function show_loader() {
 
 // creating loading animation if not present
 if (typeof($('#pg_loading')[0]) == 'undefined') {
 $('body').append('<div id="pg_loading"></div>');
 }
 
 loader_w = $('#pg_loading').outerWidth();
 loader_h = $('#pg_loading').outerHeight();
 
 loader_l = Math.round(($(document).width() - loader_w)/2);
 
 if($.browser.opera) {
 loader_l = Math.round(($('body').width() - loader_w)/2);
 }
 
 loader_t = $(document).scrollTop() + Math.round(($(window).height() - loader_h)/2);
 
 $('#pg_loading').css({
 left: loader_l,
 top: loader_t,
 zIndex: 1000
 });
 
 $('#pg_loading').fadeIn('normal');
 }
 
 /**
 * hides the loading animation
 */
 function hide_loader() {
 $('#pg_loading').fadeOut('normal');
 }
 
 //-----------------------------------------------------

 /**
 * simple firebug debug function
 */
 function debug(param) {
 
 if (typeof(param) == "object") {
 output = 'OBJECT\n';
 for ( a in param) {
 output += "\t" + a + ": " + param[a] + "\n"; 
 }
 
 param = output;
 }
 
 if (window.console && window.console.log) {
 window.console.log('[generic_gallery] '+ param);
 } else {
 //alert(param);
 }
 };

})(jQuery);
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>');
}


function open_legend() {
 $("#legenda").css("display","block");
}
function close_legend() {
 $("#legenda").css("display","none");
}

/*
function open_popover() {
 alert(123);
 
}
*/
function write_flash(filename, width, height, imagepath, paramstr) {
 
 
 document.write("<script type='text/javascript'>");
 document.write("AC_FL_RunContent(");
 document.write("'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',");
 document.write("'width', "+width+",");
 document.write("'height', "+height+",");
 document.write("'src', 'flash/"+filename+"',");
 document.write("'quality', 'high',");
 document.write("'pluginspage', 'http://www.macromedia.com/go/getflashplayer',");
 document.write("'align', 'middle',");
 document.write("'play', 'true',");
 document.write("'loop', 'true',");
 document.write("'scale', 'showall',");
 document.write("'wmode', 'transparent',");
 document.write("'devicefont', 'false',");
 document.write("'id', '"+filename+"',");
 document.write("'bgcolor', 'transparent',");
 document.write("'name', '"+filename+"',");
 document.write("'menu', 'true',");
 document.write("'allowFullScreen', 'false',");
 document.write("'allowScriptAccess','sameDomain',");
 document.write("'movie', 'flash/"+filename+"',");
 document.write("'flashvars', '"+paramstr+"',");
 document.write("'salign', ''");
 document.write(");");
 document.write("</script>");
 

 
}

function show_video_file(videofile,previewfile,sizex,sizey,autoplay,fullscr)
{
 auto_play = false;
 full_screen = false;
 if (autoplay != null){
 auto_play = true;
 }
 if (fullscr != null){
 full_screen = true;
 }
 var vars = {
 width:sizex,
 height:sizey,
 file:videofile,
 image:previewfile,
 fullscreen:full_screen,
 javascriptid:'video',
 enablejs:'true',
 backcolor:'73BF43',
 frontcolor:'FFFFFF',
 lightcolor:'FFFFFF',
 screencolor:'000000',
 autostart:auto_play,
 controlbar:'over'
 };
 
 var params = {
 allowscriptaccess:'always',
 allowfullscreen:full_screen,
 wmode:'transparent'
 };
 
 swfobject.embedSWF("flash/player.swf", "video", sizex, sizey, "9.0.0",'', vars, params);
}


function changeHTML(objectid,newtext){
 document.getElementById(objectid).innerHTML = newtext;
}

/*
* 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,scroll,tracking){
 
 if (tracking == undefined) tracking = false;
 
 if (tracking) {
 pageTracker._trackEvent('heaeder', 'Click', 'Radio popup');
 }
 
 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="+scroll+", status=no, menubar=no, resizable=no, directories=no");
}


function set_background(item_id, bg_class) {
 
 $("#bg_"+item_id).toggleClass(bg_class);
}


function toggle_visibility() {
 if ($("#oblak").css("display") == "none"){
 $("#oblak").css("display","block");
 } else {
 $("#oblak").css("display","none");
 }
}

function next_item() {
 
 var next;
 var current = 0;
 var items_count = $("#tutorial .item").length;
 
 for (var i = 0; i<items_count; i++){
 if ($("#item_"+i).css("display") == "block") {
 current = i;
 $("#item_"+i).css("display","none");
 next = i + 1;
 }
 }
 current = next;
 $("#item_"+next).css("display","block");
 
 if (next == items_count-1) {
 $("#tutorial-forward-button").css("display","none");
 $("#tutorial-goto-playz").css("display","block");
 $("#tutorial-more-about").css("display","block");
 } 
 if (current > 0) {
 $("#tutorial-back-button").css("display","block");
 }
 
}

function previous_item() {
 
 var previous;
 var current;
 var items_count = $("#tutorial .item").length;
 
 for (var i = 0; i<items_count; i++){
 if ($("#item_"+i).css("display") == "block") {
 current = i;
 $("#item_"+i).css("display","none");
 previous = i - 1;
 }
 }
 $("#item_"+previous).css("display","block");
 current = previous;
 if (previous == 0) {
 $("#tutorial-back-button").css("display","none");
 } 
 if (current < items_count) {
 $("#tutorial-forward-button").css("display","block");
 $("#tutorial-goto-playz").css("display","none");
 $("#tutorial-more-about").css("display","none");
 }
 
 
}

function show_gallery_item (galID,itemID) {
 $(galID+" span").css("display","none");
 $(".izbirnik .item a").removeClass("active");
 $("#bimg_"+itemID).css("display","block");
 $("#th_"+itemID).addClass("active");
 return false;
}

/*
 * 
 * telephone slider na ponudbi -> vstopna stran
 */

function init_telephone_showcase(paket) {
 
 if ($('#orto-telefoni').length > 0) {
 
 if (paket == '' || paket == undefined) paket = 0;
 
 $.ajax({
 url: 'ajax.request.php?action=orto_telefoni',
 type:'POST',
 dataType:'html',
 data: {ID: paket},
 success: function(rsp) {
 $('#ajax_telefoni').html(rsp);
 set_telephone_slider();
 }
 });
 
 
 }
 
}

function set_telephone_slider() {
 if ($('#orto-telefoni')) {
 
 var sliding_width = 220;
 var num_elements = $(".telefon-box").length;
 var holder_width = num_elements * 220;
 var holder_position = 0;
 
 $(".holder").css( 'width', holder_width);
 
 if (holder_position == 0) $("#back-button").css("display","none");
 if (num_elements < 2) {
 $("#forward-button").css("display","none");
 } else {
 $("#forward-button").css("display","block");
 }
 
 $("#forward-button").click(function(){
 
 holder_position = holder_position - sliding_width;
 $(".holder").animate({left: holder_position+'-'+sliding_width+'px'},'slow');
 
 if (holder_position < 0) $("#back-button").css("display","block");
 if (holder_position == -holder_width + sliding_width) $(this).css("display","none");
 
 return false;
 });
 
 $("#back-button").click(function(){
 
 holder_position = holder_position + sliding_width;
 $(".holder").animate({left: holder_position+'+'+sliding_width+'px'},'slow');
 
 if (holder_position == 0) $(this).css("display","none");
 if (holder_position > -holder_width + sliding_width) $("#forward-button").css("display","block");
 
 return false;
 });
 }
}


function set_benefiti_slider () {
 if ($("#muziq-benefiti-selector")) {
 
 var container_width = 500;
 var item_width = 125;
 var num_items = $("#benefiti-slider .item").length;
 var slider_width = num_items * item_width;
 var end_position = container_width - slider_width;
 var slider_position = 0;
 
 $("#benefiti-slider").css('width',slider_width);
 $("#btn-left, #btn-right").click(function() { return false; });
 
 $("#btn-left").mousedown(function(){
 $("#benefiti-slider").animate({left: 0}, 'slow');
 });
 
 $("#btn-right").mousedown(function(){
 $("#benefiti-slider").animate({left: end_position}, 'slow');
 });
 
 $("#btn-left, #btn-right").mouseup(function(){ $("#benefiti-slider").stop(); });
 
 } 
}

function set_benefit_content(itemID) {
 
 $("#benefiti-slider .selected").removeClass("selected");
 $("#b"+itemID).addClass("selected");
 
 
 $.ajax({
 url: 'ajax.request.php?action=benefiti',
 type:'POST',
 dataType:'json',
 data: {ID: itemID},
 success: function(rsp) {
 $('#muziq-benefiti').html(rsp.html);
 
 var vars = rsp.flash_vars;
 
 var params = {
 allowscriptaccess:'always',
 allowfullscreen: false,
 wmode: 'transparent'
 };
 
 swfobject.embedSWF(rsp.muziq_tv_swf, "z_muziq_tv_container", "480", "320", "9.0.0", params, vars);
 }
 });
 
 
 //$('#muziq-benefiti').load('ajax.request.php?action=benefiti&ID='+itemID)
 
 //$('#muziq-benefiti').html(zan_geturl('ajax.request.php?action=benefiti&ID='+itemID));
}

function zan_geturl(addr) {
 var r = $.ajax({
 type: 'GET',
 url: addr,
 async: false
 }).responseText;
 return r;
}




function set_muziqnews_slider() {
 if ($("#current-news")) {

 var sliding_width = 597;
 var num_elements = $("#current-news .item").length;
 var slider_width = num_elements * 597;
 var slider_position = 0;
 
 $("#current-news .slider").css( 'width', slider_width);
 if (slider_position == 0) $("#muziq-news-back").css("display","none");
 
 $("#muziq-news-forward").click(function(){
 slider_position = slider_position - sliding_width;
 $("#current-news .slider").animate({ left: slider_position+'-'+sliding_width+'px'}, 'slow');
 if (slider_position < 0) $("#muziq-news-back").css("display","block");
 if (slider_position == -slider_width + sliding_width) $(this).css("display","none");
 return false;
 });
 
 $("#muziq-news-back").click(function(){
 slider_position = slider_position + sliding_width;
 $("#current-news .slider").animate({ left: slider_position+'+'+sliding_width+'px'}, 'slow');
 if (slider_position == 0) $(this).css("display","none");
 if (slider_position > -slider_width + sliding_width) $("#muziq-news-forward").css("display","block"); 
 return false;
 });
 }
}


/*
 * 
 * ORTO feed 
 */

function set_ortofeed_slider() {
 if ($('#ortofeed')) {
 
 var conteiner_height = $("#ortofeed .conteiner").height();
 var slider_height = $("#orto-feed-slider").height();
 var end_pos = conteiner_height - slider_height;
 
 $("#down-button, #up-button").click(function(){ return false; });
 
 $("#up-button").mousedown(function(){
 $("#orto-feed-slider").animate({top: 0}, 'slow');
 });
 
 $("#down-button").mousedown(function(){
 $("#orto-feed-slider").animate({top: end_pos}, 'slow');
 });
 
 $("#down-button, #up-button").mouseup(function(){
 $("#orto-feed-slider").stop();
 });
 }
}


/*function set_topplayz_slider () {
 if ($("#top-playz-holder").length > 0) {
 
 var conteiner_width = $("#top-playz-holder").width();
 var slider_width = $("#top-playz-slider").width();
 var end_pos = conteiner_width - slider_width;
 
 $("#top-playz-left, #top-playz-right").click(function(){ return false; });
 
 $("#top-playz-left").mousedown(function(){
 $("#top-playz-slider").animate({left: 0}, 'slow');
 });
 
 $("#top-playz-right").mousedown(function(){
 $("#top-playz-slider").animate({left: end_pos}, 'slow');
 });
 
 $("#top-playz-left, #top-playz-right").mouseup(function(){
 $("#top-playz-slider").stop();
 });
 
 }
}*/

function set_topplayz_slider () {
 // config
 var mover_offset = 2;
 var mover_interval = 100;
 
 if ($("#top-playz-holder").length > 0) {
 var container_width = $("#top-playz-holder").width();
 
 var slider_width = $("#top-playz-slider").width();
 var end_pos = container_width - slider_width; 
 
 var mover_stoped = false;
 
 if (slider_width>container_width) {
 var container1 = $("#top-playz-slider")[0];
 var container2 = container1.cloneNode(true);
 
 $(container2).css('left', $(container1).width());
 container1.parentNode.appendChild(container2);
 
 container1 = $(container1).css('left', 0);
 container2 = $(container2);
 
 var mover = function() {
 //$('#tweet').html(Math.random());
 
 container1.css('left', parseInt(container1.css('left'))-mover_offset);
 container2.css('left', parseInt(container2.css('left'))-mover_offset);
 
 if (parseInt(container2.css('left'))<0) {
 container1.css('left', slider_width+parseInt(container2.css('left')));
 var tmp = container1;
 container1 = container2;
 container2 = tmp;
 }
 }
 
 var moverInst = setInterval(mover, mover_interval);
 
 var cancelMover = function() {
 mover_stoped = true;
 if (container2) {
 var c = container2[0];
 var p = c.parentNode;
 p.removeChild(c);
 clearInterval(moverInst);
 container2 = null;
 }
 };
 
 var pauseMover = function() {
 clearInterval(moverInst);
 }
 
 $('#top-playz-holder').hover(pauseMover, function() {
 if (!mover_stoped) {
 moverInst = setInterval(mover, mover_interval);
 }
 });
 } else {
 var cancelMover = function() {};
 }
 
 $("#top-playz-left, #top-playz-right").click(function(){ return false; });
 
 $("#top-playz-left").mousedown(function(){
 cancelMover();
 $("#top-playz-slider").animate({left: 0}, 'slow');
 });
 
 $("#top-playz-right").mousedown(function(){
 cancelMover();
 $("#top-playz-slider").animate({left: end_pos}, 'slow');
 });
 
 $("#top-playz-left, #top-playz-right").mouseup(function(){
 $("#top-playz-slider").stop();
 });
 
 }
}


function set_friend_on_playz_slider () {
 
 if ($("#friends-on-playz-holder").length > 0) {
 
 
 var conteiner_width = $("#friends-on-playz-holder").width();
 var slider_width = $("#friends-on-playz-slider").width();
 var end_pos = conteiner_width - slider_width;
 
 
 $("#friends-on-playz-left, #friends-on-playz-right").click(function(){ return false; });
 
 $("#friends-on-playz-left").mousedown(function(){
 $("#friends-on-playz-slider").animate({left: 0}, 'slow');
 });
 
 $("#friends-on-playz-right").mousedown(function(){
 $("#friends-on-playz-slider").animate({left: end_pos}, 'slow');
 });
 
 $("#friends-on-playz-left, #friends-on-playz-right").mouseup(function(){
 $("#friends-on-playz-slider").stop();
 });
 
 }
 
}



function parse_message_playz(message) {
 var return_array = {};

 var patterns = {
 'location' : /#([^$\* ]*)/,
 'music' : /\$([^#\*]*)/,
 'status' : /\*([^#\$]*)/
 };
 
 var pattern;
 var matches;
 for (var key in patterns) {
 pattern = patterns[key];

 matches = message.match(pattern);
 if (matches && matches[1]) {
 return_array[key] = matches[1];
 }
 }
 return return_array;
}




function get_authorised_dealers(id) {
 
 $.ajax({
 url:'ajax.request.php?action=pooblasceni_prodajalci',
 type:'POST',
 dataType:'html',
 data: {ID: id},
 success: function(rsp) {
 $('#list-prodajna-mesta').html(rsp);
 }
 });
 
}




/* form uploadfile field formation
 * 
 * */

var W3CDOM = (document.createElement && document.getElementsByTagName);

$.fn.renderFileUpload = function() {
 if ($('div.fakefile').size()==0) {
 var fakeFileUpload = document.createElement('div');
 fakeFileUpload.className = 'fakefile';
 fakeFileUpload.appendChild(document.createElement('input'));
 var button = document.createElement('span');
 button.className = 'button';
 fakeFileUpload.appendChild(button);
 } else {
 fakeFileUpload = $('div.fakefile').get(0);
 }

 return this.each(function() {
 if (!W3CDOM) return;
 
 $(this).addClass('hidden_file');
 
 var clone = fakeFileUpload.cloneNode(true);
 
 this.parentNode.appendChild(clone);
 this.relatedElement = clone.getElementsByTagName('input')[0];
 this.btn = clone.getElementsByTagName('span')[0];
 this.onchange = this.onmouseout = function () {
 this.relatedElement.value = this.value;
 }
 this.onmouseover = function() {
 this.btn.style.backgroundPosition = 'bottom left';
 }
 this.onmouseout = function() {
 this.btn.style.backgroundPosition = 'top left';
 }
 });
}

$.fn.centerScreen = function(loaded) {
 return this.each(function() {
 var obj = $(this);
 if(!loaded) {
 obj.css('top', $(window).scrollTop()+$(window).height()/2-obj.height()/2);
 obj.css('left', $(window).scrollLeft()+$(window).width()/2-obj.width()/2);
 $(window).resize(function() {
 obj.centerScreen(!loaded);
 });
 $(document).scroll(function() {
 obj.centerScreen(!loaded);
 });
 $(window).scroll(function() {
 obj.centerScreen(!loaded);
 });
 } else {
 obj.stop();
 obj.animate({
 top: $(window).scrollTop()+$(window).height()/2-obj.height()/2,
 left: $(window).scrollLeft()+$(window).width()/2-obj.width()/2
 }, 200, 'linear');
 }
 });
}


$(document).ready(function() {
 set_ortofeed_slider();
 //set_telephone_slider();
 set_topplayz_slider();
 set_muziqnews_slider();
 set_friend_on_playz_slider();
 $('input[type=file]').renderFileUpload();
});

/*
* STAR RATING
*/
$(function() {
 $('ul.star-rating-votable li a').click(function() { 
 if ($(this).parent().hasClass('current-rating')) {
 return false;
 }
 
 var container = $($(this).parents('ul.star-rating-votable')[0]);
 var rate = parseInt(this.rel.replace(/^Rate/, ''));
 
 $('li', container).hide();
 $('li.current-rating', container).css('width', parseInt(100*rate/5)+'%').show();
 
 var match = $('li.current-rating a', container).attr('rel').match(/^(.*)\|(.*)$/);
 var data = {
 type: match[1],
 id: match[2],
 rate:this.rel
 };
 
 $.ajax({
 url:'ajax.request.php?action=star_rate',
 type:'POST',
 dataType:'json',
 data: data,
 success: function(rsp) {
 if (rsp.success) {
 $('li.current-rating', container).css('width', parseInt(100*rsp.star_rate/5)+'%');
 } else {
 $('li', container).show();
 $('li.current-rating', container).hide();
 }
 },
 error:function() {
 $('li', container).show();
 $('li.current-rating', container).hide();
 }
 });
 
 return false;
 
 });

 $('ul.ortotrip-rating-votable li a').click(function() {
 // submission function
 var submit = function(data, container) {
 var data = $('#ortotrip_castvote_dlg').data('data');

 $.ajax({
 url:'ajax.request.php?action=ortotrip_rate',
 type:'POST',
 dataType:'json',
 data: data,
 success: function(rsp) {
 var container = $('#ortotrip_castvote_dlg').data('container');
 if (rsp.success) {
 var userRate = parseInt(rsp.star_rate.replace('Rate', ''));
 $('li.current-rating', container).css('width', parseInt(100*userRate/5)+'%');

 if (typeof(params.currentVoteSelector.closest)!='undefined' && params.currentVoteSelector.closest) {
 var closest = $(container).closest(params.currentVoteSelector.closest);
 } else {
 var closest = $(container);
 }
 var currRateEl = $(params.currentVoteSelector.childs, closest);

 if (typeof(params.currentVoteSelector.topLevel)!='undefined' && params.currentVoteSelector.topLevel) {
 currRateEl = currRateEl.add(params.currentVoteSelector.topLevel, document.body);
 }

 currRateEl.each(function() {
 var score = parseInt($(this).html());
 score += userRate;
 $(this).html(score);
 });

 $('#ortotrip_castvote_dlg').data('has_voted', true);
 
 if (rsp.has_signed_up) {
 $('#ortotrip_castvote_dlg').data('participating', true);

 $('#ortotrip_castvote_dlg .inner .top, #ortotrip_castvote_dlg .inner .bottom, #ortotrip_castvote_dlg .inner .saving').hide();
 $('#ortotrip_castvote_dlg .inner').prepend('<div class="thanks">Hvala za oddan glas. Uvrstili smo te v nagradno žrebanje.</div>');
 setTimeout(function() {
 $('#ortotrip_castvote_dlg').fadeOut();
 }, 2000);
 } else {
 $('#ortotrip_castvote_dlg').fadeOut();
 }
 } else {
 alert('Zgodila se je napaka pri glasovanju. Poiskusite kasneje!');
 $('li', container).show();
 $('li.current-rating', container).hide();
 $('#ortotrip_castvote_dlg').fadeOut();
 }
 },
 error:function() {
 alert('Zgodila se je napaka pri glasovanju. Poiskusite kasneje!');
 $('li', container).show();
 $('li.current-rating', container).hide();
 $('#ortotrip_castvote_dlg').fadeOut();
 }
 });
 }

 var createForm = function() {
 // create form if form does not exist
 if ($('#ortotrip_castvote_dlg').size()==0) {
 $(document.body).append(
 '<div id="ortotrip_castvote_dlg" style="display:none" class="pngfix">'+
 '<div class="inner">'+
 '<div class="saving">Ocena se shranjuje ...</div>'+
 '<div class="top">'+
 '<label>Želim samo oddati točke za prispevek.</label>'+
 '<button name="justvote"></button>'+
 '</div>'+

 '<div class="bottom">'+
 '<span>Želim glasovati in <strong>sodelovati v nagradnem žrebanju</strong> za telefon NOKIA N97 mini. </span>'+
 '<button></button>'+
 '<label>Vpiši svoj email naslov:</label>'+
 '<input type="text" name="ortotrip_castvote_email" />'+
 '</div>'+
 '<a class="close" href="#">zapri</a>'+
 '</div>'+
 '</div>'
 );
 $('#ortotrip_castvote_dlg input[name=ortotrip_castvote_email]').focus(function() {
 $('#ortotrip_castvote_dlg input[value=castandparticipate]').attr('checked', 'checked');
 });
 $('#ortotrip_castvote_dlg input[value=castandparticipate]').click(function() {
 $('#ortotrip_castvote_dlg input[name=ortotrip_castvote_email]').focus();
 });
 $('#ortotrip_castvote_dlg button').click(function() {
 var email = '';

 if (this.name!='justvote') {
 if (!$('#ortotrip_castvote_dlg input[name=ortotrip_castvote_email]').val()) {
 alert('Vnos e-mail naslova je obvezen za udeležbo v nagradni igri!');
 return false;
 }
 email = $('#ortotrip_castvote_dlg input[name=ortotrip_castvote_email]').val();
 }
 //$('#ortotrip_castvote_dlg').
 var data = $('#ortotrip_castvote_dlg').data('data') ;
 data.email = email;
 $('#ortotrip_castvote_dlg .inner .top, #ortotrip_castvote_dlg .inner .bottom').hide();
 $('#ortotrip_castvote_dlg').data('data', data);
 $('#ortotrip_castvote_dlg .inner .saving').show();
 submit();
 });
 $('#ortotrip_castvote_dlg a.close').click(function() {
 var container = $('#ortotrip_castvote_dlg').data('container');

 if (!$('#ortotrip_castvote_dlg').data('has_voted')) {
 $('li', container).show();
 $('li.current-rating', container).hide();
 }

 $('#ortotrip_castvote_dlg').fadeOut();
 return false;
 });
 }
 }

 var showForm = function() {
 var data = $('#ortotrip_castvote_dlg').data('data');
 var container = $('#ortotrip_castvote_dlg').data('container');

 $('#ortotrip_castvote_dlg .inner .top, #ortotrip_castvote_dlg .inner .bottom').show();
 $('#ortotrip_castvote_dlg .inner .saving').hide();
 $('#ortotrip_castvote_dlg input[name=ortotrip_castvote_email]').val(params.email);
 $('#ortotrip_castvote_dlg input[value=castandparticipate]').attr('checked', 'checked');

 var position = $(boxContainer).offset();
 position.left -= 20;
 position.top -= 162;
 $('#ortotrip_castvote_dlg').css(position).fadeIn();
 if (typeof(DD_belatedPNG)!='undefined') {
 DD_belatedPNG.fix('.pngfix');
 }
 }

 if ($(this).parent().hasClass('current-rating')) {
 return false;
 }

 // preparing params
 var container = $(this).parents('ul.ortotrip-rating-votable:first');
 var boxContainer = $(container).parents('.ortotrip-rating:first');
 var rate = parseInt(this.rel.replace(/^Rate/, ''));

 /*
 * 0 ... post id
 * 1 ... default email (only for logged users)
 * 2 ... is already participating
 */
 var params = eval('('+$('li.current-rating a', container).attr('rel')+')');
 var data = {
 id: params.id,
 rate: this.rel
 };

 // fix stars
 $('li', container).hide();
 $('li.current-rating', container).css('width', parseInt(100*rate/5)+'%').show();

 createForm();
 $('#ortotrip_castvote_dlg').data('data', data);
 $('#ortotrip_castvote_dlg').data('container', container);

 $('#ortotrip_castvote_dlg').data('has_voted', false);
 if (!parseInt(params.participator) && !$('#ortotrip_castvote_dlg').data('participating')) {
 showForm();
 } else {
 submit();
 }
 
 return false;

 });

});

/*
* Playz location selector
*/
var playz_location_myplayz_events = function(cont) {
 cont = $(cont);
 
 var reload = function() {
 var data = {};
 try {
 data = eval('('+$('input.playz_location_other_params', cont).val()+')');
 } catch (e) {
 data = {};
 };
 
 if (typeof(data.length)!='undefined') data = {};
 
 data.id = cont.attr('id');
 data.type = 'my-playzes';
 data.page = $('.myplayz .pageselector span.selected a').attr('rel');
 data.filter_text = $('.myplayz .filter_text', cont).val();
 
 var height = $('.myplayz', cont).height();
 $('.myplayz', cont).css('height', height);
 $('.myplayz', cont).html('Nalagam podatke ...');
 
 $.ajax({
 url:'ajax.request.php?action=playz-location-selector',
 type:'post',
 cache:false,
 data: data,
 dataType: 'json',
 success:function(rsp) {
 $('.myplayz', cont).html(rsp.html);
 $('.myplayz', cont).css('height', 'auto');

 var id;
 id = $('.current_myplayz', cont).val();
 if (id) {
 var li = $('.myplayz .items li a[rel="'+id+'"]').parents('li');
 if (li.size()>0) {
 $(li[0]).addClass('selected');
 }
 }

 playz_location_myplayz_events(cont);
 }
 });
 
 return false;
 }
 
 $('.myplayz .pageselector a', cont).click(function() {
 $('.myplayz .pageselector span', cont).removeClass('selected');
 $($(this).parents('span')[0]).addClass('selected');
 reload();
 return false;
 });
 $('.myplayz .items li a', cont).click(function() {
 var event = jQuery.Event('myplayzChange');
 $('.current_myplayz', cont).val(this.rel);
 event.id = parseInt(this.rel);
 event.code = $('.code', $(this).parent()).html().replace(/(^\s+)|(\s+$)/g, '');
 event.name = $('.name', $(this).parent()).html().replace(/(^\s+)|(\s+$)/g, '');
 event.address = $('.address', $(this).parent()).html().replace(/(^\s+)|(\s+$)/g, '');
 event.playz_id = $('.playz_id', $(this).parent()).html().replace(/(^\s+)|(\s+$)/g, '');
 $('.myplayz .items li', cont).removeClass('selected');
 $($(this).parents('li')[0]).addClass('selected');
 cont.trigger(event);
 return false;
 });
 
 $('.myplayz .filter_text').keydown(function(e) {
 if (e.keyCode==13) {
 reload();
 return false;
 } 
 
 });
 
 $('.myplayz .filter_enforce').click(reload);
}

var playz_location_lastvisited_events = function(cont) {
 cont = $(cont);
 
 var reload = function() {
 var data = {};
 try {
 data = eval('('+$('input.playz_location_other_params', cont).val()+')');
 } catch (e) {
 data = {};
 };
 
 if (typeof(data.length)!='undefined') data = {};
 
 data.id = cont.attr('id');
 data.type = 'last-visited';
 data.page = $('.lastvisited .pageselector span.selected a').attr('rel');
 data.filter_text = $('.lastvisited .filter_text', cont).val();
 
 var height = $('.lastvisited', cont).height();
 $('.lastvisited', cont).css('height', height);
 $('.lastvisited', cont).html('Nalagam podatke ...');
 
 $.ajax({
 url:'ajax.request.php?action=playz-location-selector',
 type:'post',
 cache:false,
 data: data,
 dataType: 'json',
 success:function(rsp) {
 $('.lastvisited', cont).html(rsp.html);
 $('.lastvisited', cont).css('height', 'auto');

 var id;
 id = $('.current_lastvisited', cont).val();
 if (id) {
 var li = $('.lastvisited .items li a[rel="'+id+'"]').parents('li');
 if (li.size()>0) {
 $(li[0]).addClass('selected');
 }
 }

 playz_location_lastvisited_events(cont);
 }
 });

 return false;
 }
 
 $('.lastvisited .pageselector a', cont).click(function() {
 $('.lastvisited .pageselector span', cont).removeClass('selected');
 $($(this).parents('span')[0]).addClass('selected');
 reload();
 return false;
 });
 $('.lastvisited .items li a', cont).click(function() {
 var event = jQuery.Event('lastvisitedChange');
 $('.current_lastvisited', cont).val(this.rel);
 event.id = parseInt(this.rel);
 event.code = $('.code', $(this).parent()).html().replace(/(^\s+)|(\s+$)/g, '');
 event.name = $('.name', $(this).parent()).html().replace(/(^\s+)|(\s+$)/g, '');
 event.address = $('.address', $(this).parent()).html().replace(/(^\s+)|(\s+$)/g, '');
 event.playz_id = $('.playz_id', $(this).parent()).html().replace(/(^\s+)|(\s+$)/g, '');
 $('.lastvisited .items li', cont).removeClass('selected');
 $($(this).parents('li')[0]).addClass('selected');
 cont.trigger(event);
 return false;
 });
 
 $('.lastvisited .filter_text').keydown(function(e) {
 if (e.keyCode==13) {
 reload();
 return false;
 } 
 
 });
 
 $('.lastvisited .filter_enforce').click(reload);

}

var playz_location_allplayz_events = function(cont) {
 cont = $(cont);
 
 var reload = function() {
 var data = {};
 try {
 data = eval('('+$('input.playz_location_other_params', cont).val()+')');
 } catch (e) {
 data = {};
 };
 
 if (typeof(data.length)!='undefined') data = {};
 
 data.id = cont.attr('id');
 data.type = 'all-playzes';
 data.page = $('.allplayz .pageselector span.selected a').attr('rel');
 data.filter_text = $('.allplayz .filter_text', cont).val();
 
 var height = $('.allplayz', cont).height();
 $('.allplayz', cont).css('height', height);
 $('.allplayz', cont).html('Nalagam podatke ...');
 
 $.ajax({
 url:'ajax.request.php?action=playz-location-selector',
 type:'POST',
 cache:false,
 data: data,
 dataType: 'json',
 success:function(rsp) {
 $('.allplayz', cont).html(rsp.html);
 $('.allplayz', cont).css('height', 'auto');

 var id;
 id = $('.current_allplayz', cont).val();
 if (id) {
 var li = $('.allplayz .items li a[rel="'+id+'"]').parents('li');
 if (li.size()>0) {
 $(li[0]).addClass('selected');
 }
 }

 playz_location_allplayz_events(cont);
 }
 });

 return false;
 };
 
 $('.allplayz .pageselector a', cont).click(function() {
 $('.allplayz .pageselector span', cont).removeClass('selected');
 $($(this).parents('span')[0]).addClass('selected');
 reload();
 return false;
 });
 $('.allplayz .items li a', cont).click(function() {
 var event = jQuery.Event('allplayzChange');
 $('.current_allplayz', cont).val(this.rel);
 event.id = parseInt(this.rel);
 event.code = $('.code', $(this).parent()).html().replace(/(^\s+)|(\s+$)/g, '');
 event.name = $('.name', $(this).parent()).html().replace(/(^\s+)|(\s+$)/g, '');
 event.address = $('.address', $(this).parent()).html().replace(/(^\s+)|(\s+$)/g, '');
 event.playz_id = $('.playz_id', $(this).parent()).html().replace(/(^\s+)|(\s+$)/g, '');
 $('.allplayz .items li', cont).removeClass('selected');
 $($(this).parents('li')[0]).addClass('selected');
 cont.trigger(event);
 return false;
 });
 
 $('.allplayz .filter_text').keydown(function(e) {
 if (e.keyCode==13) {
 reload();
 return false;
 } 
 
 });
 
 $('.allplayz .filter_enforce').click(reload);
 
}

function init_playz_location_selector(rel) {
 if (typeof(rel)=='undefined') {
 rel = null;
 }
 
 $('.playz_location_selector', rel).each(function() {
 var cont = this;

 playz_location_myplayz_events(this);
 playz_location_lastvisited_events(this);
 playz_location_allplayz_events(this);

 $('.playz_location_selector_tabs a', this).click(function() {
 $('.playz_location_selector_tabs li', cont).removeClass('selected');
 $($(this).parents('li')[0]).addClass('selected');
 $('.playz_location_selector_tab', cont).hide();
 $('.playz_location_selector_tab.'+this.rel, cont).show();
 $('.current_type', cont).val(this.rel);
 return false;
 });
 });
}

$(function() {
 init_playz_location_selector();
 
});

 
var DelayedTask = function(callback, delayTime, scopeObj) {
 var timer = null;
 var delay = delayTime;
 var cb = callback;
 var scope = scopeObj;
 var dt = {
 start: function() {
 if (timer) {
 clearTimeout(timer);
 timer = null;
 }
 timer = setTimeout(function() {
 cb.call(scope, dt);
 }, delay);
 },
 getCallback: function() {
 return cb;
 }
 }
 return dt;
};

$(function() {
 var friend_search_fun = new DelayedTask(function(dt) {
 var text = $('input', $(this).parents('.friend-search')[0]).val().toLowerCase();
 text = text.replace(/^\s+|\s+$/, '');
 
 var show_users = function(rsp) {
 dt.ajaxRequestRunning = false;
 $('#user-friends .Scroller-Container .search-status').remove();
 $('#user-friends .Scroller-Container .user').remove();
 $('#user-friends .Scroller-Container .other-users').remove();
 $('#user-friends .Scroller-Container').append('<div class="other-users">Ostali uporabniki</div>');
 
 if (rsp.success) {
 var fc = $('#user-friends .Scroller-Container');
 
 for (var i=0; i<rsp.users.length; i++) {
 var user = rsp.users[i];
 fc.append(
 '<div class="friend user">'+
 '<span class="avatar"><a href="'+user.url+'"><img src="'+user.avatar+'"/></a></span>'+
 '<span class="nickname"><a href="'+user.url+'">'+user.nick+'</a></span>'+
 '</div>'); 
 }
 
 if (rsp.moreResults) {
 $('#user-friends .Scroller-Container').append('<div class="search-status">Prikazujejo se zgolj prvih 10 zadetkov. <a href="'+rsp.moreResultsUrl+'">Preglej vse</a></div>');
 }
 }
 fix_scroller();
 };
 
 var fix_scroller = function() {
 scroller = new jsScroller(document.getElementById("Container"), scroller_width, scroller_height);
 scrollbar = new jsScrollbar (document.getElementById("Scrollbar-Container"), scroller, true, scrollbarEvent);
 scrollbar._scrollDist = 10;
 }
 
 if (text!='' && text!='Poišči frende...') {
 if (text==dt.lastSearch) {
 return;
 } else {
 dt.lastSearch = text;
 }
 
 if (dt.ajaxRequestRunning == false) {
 dt.ajaxRequestRunning = true;
 $('#user-friends .Scroller-Container').append('<div class="search-status loading">Iščem prijatelje ...</div>');
 $.ajax({
 url:'ajax.request.php?action=user_search',
 type:'POST',
 dataType:'json',
 data:{
 text:text
 },
 success:show_users,
 error:show_users
 });
 }
 $('#user-friends .friend').each(function() {
 var nickname = $('.nickname a', this).html().toLowerCase();
 if (nickname.indexOf(text)!=-1) {
 $(this).show();
 } else {
 $(this).hide();
 }
 });
 
 fix_scroller();
 } else {
 $('#user-friends .friend').show();
 $('#user-friends .Scroller-Container .user').remove();
 $('#user-friends .Scroller-Container .other-users').remove();
 fix_scroller();
 }
 return false;
 }, 1000, $('.friend-search input'));
 friend_search_fun.lastSearch = '';
 friend_search_fun.ajaxRequestRunning = false;
 $('.friend-search button').click(friend_search_fun.getCallback());
 $('.friend-search input').focus(function() {
 if (this.value=='Poišči frende...') {
 this.value = '';
 }
 }).blur(function() {
 if (this.value=='') {
 this.value='Poišči frende...';
 }
 }).keyup(function() {
 friend_search_fun.start();
 });
});
 
jQuery.fn.textLimiter = function(cf) {
 return this.each(function(){
 var el = $(this);
 
 if (typeof(cf)=='undefined') {
 cf = {};
 }
 
 if (typeof(cf.maxLength)=='undefined') {
 cf.maxLength = 5;
 }
 
 if (typeof(cf.text)=='undefined') {
 cf.text = 'število preostalih znakov: {remaining}';
 }
 
 var setText = function() {
 var data = {
 current: el.val().length,
 remaining: cf.maxLength - el.val().length,
 total: cf.maxLength
 }
 
 var text = cf.text;
 for (var key in data) {
 text = text.replace(new RegExp('{'+key+'}'), data[key]);
 }
 
 $(cf.element).html(text);
 
 if (el.val().length>cf.maxLength) {
 el.val(el.val().substring(0,cf.maxLength));
 }
 }
 setText();
 
 el.keydown(function(e) {
 //Get the event object (for IE) 
 var ob = e || event; 
 //Get the code of key pressed 
 var keyCode = ob.keyCode; 
 //Check if it has a selected text 
 var hasSelection = document.selection? document.selection.createRange().text.length > 0 : this.selectionStart != this.selectionEnd; 
 //return false if can't write more 
 return !(this.value.length >= cf.maxLength && (keyCode > 50 || keyCode == 32 || keyCode == 0 || keyCode == 13) && !ob.ctrlKey && !ob.altKey && !hasSelection); 
 }).keyup(setText);
 
 
 });
};

$(function() {
 if ($('.ad-gallery').size()>0) {
 var galleries = $('.ad-gallery').adGallery();
 }
});
$(document).ready(function(){
 $('.popup-pogoji-href').click(function(){
 var popupUrl = $(this).attr('href');
 //var popupTitle = $('.popup-pogoji-href span').text();
 
 openwin(popupUrl,'',500,600,'yes');
 return false;
 });
 $('.video_player_link').click(function() {
 $(this).modal({width:600, height:440, src:this.href}).open(); 
 return false;
 });
});
//$(document).ready(function(){
// if ($('.popover').size()>0) {
// $(".popover").ceebox({htmlWidth:600,htmlHeight:444});
// }
//});
function open_popover() {
 //$.ceebox.show('', 'popover_video.php', false);
 $(this).modal({width:600, height:440}).open();
}
function open_popover_trip() {
 //$.ceebox.show('', 'popover_video.php', false);
 href = TRIP_FLASH_HREF;
 $(this).modal({width:640, height:352, src:href}).open();
}

function open_popover_stream() {
 //$.ceebox.show('', 'popover_video.php', false);
 href = "/popover_stream.php";
 $(this).modal({width:960, height:720, src:href}).open();
}

function showTelefoni(xml_file) {
 
 var flashvars = {};
 var params = {};
 var attributes = {};
 
 flashvars.xmlpath = xml_file;
 
 params.base= 'flash/';
 params.play = 'true';
 params.loop = 'true';
 
 swfobject.embedSWF('flash/telefoni.swf', 'flash-promo-telefoni', '190', '310', '8', '', flashvars, params, attributes);
}


function swapTelefoni(mode) {
 
 xml_file = 'http://www.orto.si/ajax.request.php?action=first-page-promo-phones'; 
 
 if (mode == 'ortoberi') {
 xml_file = 'http://www.orto.si/ajax.request.php?action=first-page-promo-phones&PackageID=507';
 } else if (mode == 'ortounulo') {
 xml_file = 'http://www.orto.si/ajax.request.php?action=first-page-promo-phones&PackageID=506';
 } else if (mode == 'ortomuziq') {
 xml_file = 'http://www.orto.si/ajax.request.php?action=first-page-promo-phones&PackageID=508';
 } else if (mode == 'all') {
 xml_file = 'http://www.orto.si/ajax.request.php?action=first-page-promo-phones';
 }
 
 showTelefoni(escape(xml_file));
}

$(function() {
 $('#improper_content').change(function() {
 if (this.value) {
 var closeDlg = function(e) {
 if (typeof(e)=='undefined') {
 var trg = false;
 } else {
 var trg = e.originalTarget;
 }

 var ex;
 try {
 var id = trg.id;
 } catch (ex) {
 return false;
 }

 if (trg &&
 ($(trg).attr('id')=='improper_content_dlg' ||
 $(trg).parents('#improper_content_dlg').size()>0)) {

 return false;
 } else {
 var el = $('#improper_content_dlg')[0];
 var p = el.parentNode;
 p.removeChild(el);
 }
 };

 var submitDlg = function() {
 $('button, textarea', dlg).attr('disabled', 'disabled');

 var data = {
 reason_type: $('.reason_type', dlg).html(),
 post_id: $('.post_id', dlg).html(),
 reason: $('textarea', dlg).val()
 }

 $.ajax({
 url:'ajax.request.php?action=improper_content',
 type:'POST',
 dataType:'json',
 data:data,
 success:function(rsp) {
 closeDlg();
 if (!rsp.success) {
 alert(rsp.msg);
 } else {
 $('#improper_content').attr('disabled', 'disabled');
 alert('Hvala za prijavo neprimerne vsebine!');
 }
 }
 });
 };

 var dialog =
 '<div id="improper_content_dlg">'+
 '<span class="reason_type">{type}</span>'+
 '<span class="post_id">{id}</span>'+
 '<div class="reason">Razlog:<br /><strong>{reason}</strong></div>'+
 '<div class="desc">Opis:<br/><textarea></textarea></div>'+
 '<div class="submit"><button class="ok">Prijavi</button><button class="cancel">Prekliči</button></div>'+
 '<div class="wrn">'+
 'Preden prijavite, preverite če zapis res krši <a href="#">pravila in pogoje</a> '+
 'sodelovanja v skupnosti. Napačna ali zlonamerna prijava je pravtako kršitev '+
 '<a href="#">pravil in pogojev</a>.'+
 '</div>'+
 '</div>';
 dialog = dialog
 .replace('{reason}', this.options[this.selectedIndex].innerHTML);

 $(document.body).append(dialog);

 var dlg = $('#improper_content_dlg').hide();
 var anchor = $('#improper_content');
 var offset = anchor.offset();

 $('.reason_type', dlg).html(this.value);
 $('.post_id', dlg).html(location.search.match(/id=([0-9]+)/)[1]);

 $('button.cancel', dlg).click(function() {closeDlg(); });
 $('button.ok', dlg).click(submitDlg);

 this.selectedIndex = 0;
 dlg.css(offset).show();
 setTimeout(function() {
 $(document.body).one('click', closeDlg)
 }, 1);
 }

 });

});


function toggle_table() {
 

 $("#opcije-box").toggleClass("hidden");
 
 if ($("#opcije-box").hasClass("hidden")) { 
 setCookie('info_table','hidden');
 } else {
 setCookie('info_table','opened');
 }
 
}
