
//checks if element/s exists and saves it in global variable $ee - element exists
function $e(selector){return (elements = $(selector)).length>0 ? window['$ee'] = elements : false}

// hover combo
$.fn.h = function(classname) {
  this.hover(function(){$(this).addClass(classname)},function(){$(this).removeClass(classname)})
}

// clear on focus
$.fn.clear_on_focus = function(word){
  var title = word || $(this).attr("title");
  if($(this).attr("value") == "" || $(this).attr("value") == null) $(this).attr("value", title)
  this.focus(function(){
    if($(this).attr("value") ==title) $(this).attr("value", "")
  })
  this.blur(function(){
    if($(this).attr("value") == "" || $(this).attr("value") == null) $(this).attr("value", title)
  })
}


//var current_video = null;
//function getUpdate(typ,pr1,pr2,swf) {
//  switch(typ){
//    case "state" :
//      if(pr1 == 0) $(current_video).removeClass('videoPlay').addClass('videoPause')
//      if(pr1 == 2) $(current_video).removeClass('videoPause').addClass('videoPlay');
//    break;
//  }
//};

//var FLVplayer = function(player_id){
//     this.movie = (navigator.appName.indexOf("Microsoft") != -1) ?  window[player_id] :  document[player_id];
//     this.playing = false;
//     this.last = null;
//}

//FLVplayer.prototype = {
//    /* Base functions */
//    play: function(obj){
//      if(obj){this.load(obj)}
//      this.sendEvent('playpause');
//      this.playing = !this.playing;
//    },
//    stop: function(){
//      this.sendEvent('stop');
//      this.playing = false;
//    },
//    /* File / item functions */
//    load: function(obj) {
//      this.movie.loadFile(obj);
//    },
//    addItem: function(obj,idx) {
//      this.movie.addItem(obj,idx);
//    },
//    removeItem: function(idx) {
//      this.movie.removeItem(idx);
//    },
//    getLength: function(swf) {
//      return this.movie.getLength();
//    },
//    getData: function(idx){
//      this.movie.itemData(idx);
//    },
//    sendEvent: function(typ,prm){
//      this.movie.sendEvent(typ,prm);
//    }
//}


// random number
Number.prototype.rnd = function(){return Math.round(Math.random()*this)}


$(document).ready(function() {

 // add js to body for css
 $(document.body).addClass('js')

 //if(jQuery.browser.safari) $(document.body).addClass('safari')


    if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
    $('span.btn').h('btn_hover')
    $('#popmenu').h("hover")
  }

    $('#popmenu').hover(
       function(){$('embed, object').css('visibility', 'hidden')},
       function(){$('embed, object').css('visibility', 'visible')}
     )

  //fix for opera to refresh whole page :-)
  if (jQuery.browser.opera) {
     $e('#allcontent')
     $('#popmenu').hover(
       function(){$ee.css("opacity", "0.99")},
       function(){$ee.css("opacity", "1")}
     )
  }



 $('.search input.txt').clear_on_focus();



  if($e('#teaser1 .slides')){
    $ee.cycle({
      speed:  800,
      timeout: 5000,
      pager:  '#teaser1 .pages',
      prev: '#teaser1 .prev',
      next: '#teaser1 .next',
      pagerEvent: 'click'
    });
  }


// za random treba staviti startingSlide: $('#teaser2 .slides > div').length.rnd(),
  if($e('#teaser2 .slides')){
   $ee.cycle({
      //fx: 'scrollLeft',
      speed: 0,
      timeout: 0,
      pager:  '#teaser2 .horizontal',
      startingSlide: 0,
      pagerEvent: 'click',
      pagerAnchorBuilder: function(idx, slide) {
         return '#teaser2 a.handle_' + idx;
      }
    });
  }


//  if($e('.video_list .slides')){
//   $ee.cycle({
//      fx: 'scrollVert',
//      speed: "normal",
//      timeout: 0,
//      pager:  '.video_list .pages',
//      prev: '.video_list .prev',
//      next: '.video_list .next',
//      pagerEvent: 'click'
//    });
//  }





  if($e('.minigallery .slides')){
    $ee.cycle({
      fx: 'scrollHorz',
      speed:  "fast",
      timeout: 0,
      prev: '.minigallery .prev',
      next: '.minigallery .next',
      prevNextClick: function (isNext, zeroBasedSlideIndex, slideElement){
        $('.minigallery .page_count span').html(++zeroBasedSlideIndex);
        $('.minigallery .img-title').html(slideElement.title);
      }
    });
  }

//var player = new FLVplayer("flvplayer")
///* FLV PLAYER PLAYLIST */
//$(".playlist_simple a").click(function(e){
//    e.preventDefault()
//    current_video == this ? player.play() : player.play({file:this.rel})
//    current_video = this;
//})


//var video_title = $('#video-title')
//var video_desc = $('#video-desc p')
//$(".playlist_complex a").click(function(e){
//    e.preventDefault()
//    current_video == this ? player.play() : player.play({file:this.rel})
//    current_video = this;
//    video_title.html($(this).find(".t").html())
//    video_desc.html($(this).find(".d").html())
//})


/* ACCORDIAN */
 var acc_last = {};
 $('.accordion .trigger').h('trigger_hover')
 $('.accordion .slide .content').hide()
 acc_last['slide']   =  $('.accordion .slide:first').addClass('selected')
 acc_last['content'] = acc_last['slide'].find('.content').slideDown("fast")
 acc_last['trigger'] = acc_last['slide'].find('.trigger').get(0)
 $('.accordion .slide .trigger').click(function(e){
  if(acc_last['trigger'] != this){
   if (acc_last['trigger']) acc_last['slide'].removeClass('selected')
   if (acc_last['content']) acc_last['content'].slideUp("fast")
   acc_last['trigger'] = this
   acc_last['slide']   = $(this).parents('.slide:first').addClass('selected')
   acc_last['content'] = acc_last['slide'].find('.content').slideDown("fast")
   }
   e.preventDefault();
 })



  if($e('.height_group')) $ee.each(function(i,g){
    $(g).find('.box .in').equalizeCols()
  })


  
  $('.sale-showmore').bind("click", function() {
    $('.sale-showmore').hide();
    $('.sale-additional').show('fast', function() {
       // Animation complete.
    })
    
  } )

})

