$('html').addClass('js');


//************************ IE6-7 ***/
$(function(){

  if(typeof document.body.style.content === 'undefined') {
  
    //************************ Emulate CSS :after and content for IE6-7 for printing ***/
    if (window.onbeforeprint !== 'undefined') {
      window.onbeforeprint = ShowLinks;
      window.onafterprint = HideLinks;
    }
    function ShowLinks() {
      $('#content a[href]').each(function() {
        $(this).data('linkText', $(this).text());
        switch(''+$(this).attr('href').match(/mailto:|http:\/\//gi)) {
          case 'http://': $(this).append(' (' + $(this).attr("href") + ')'); break;
          case 'mailto:': break;
          default: $(this).append(' ('+ (''+window.location).match(/http:\/\/.+?\//gi) +'' + $(this).attr("href") + ')');
        }
      });
    }
    function HideLinks() {
      $('#content a[href]').each(function() {
        $(this).text($(this).data('linkText'));
      });
    }
   
  }
 
});


/*HOME SLIDESHOW*/
$(window).load(function(){
	$('.slide').pngFix( {blankgif: 'images/blank.gif'} )
	$('#slides').cycle({
		fx: 'fade',
		timeout: 4000
	});
});



//************************ Lightbox ***/
$(function(){

$('.lightbox').lightBox();

});


//************************ Product image gallery ***/
$(function(){

var itemGall = {
  el: $('#item-gall'),
  info: $('.info','#item-gall'),
  thumbs: $('.info ul li','#item-gall'),
  bigImg: $('.img-big','#item-gall')
}

itemGall.thumbs.first().addClass('active');
itemGall.thumbs.children().click(function(){
  var imgLink = $(this).attr('href');
  var imgAlt = $(this).attr('title');
  var imgBig = itemGall.bigImg.children();
  $(this).parent().addClass('active').siblings().removeClass('active');
  itemGall.bigImg.addClass('loading');
  if ( imgBig.attr('src') !== imgLink ) {   
    imgBig.animate({ opacity: 0 }, function(){
      var img = new Image();
      $(img).load(function(){   
        $(this).css({opacity: 0});
        itemGall.bigImg.removeClass('loading').html(this);
        $(this).animate({opacity: 1}).attr('alt',imgAlt); $(this).attr("title", imgAlt);
      }).error(function(){}).attr('src', imgLink);
    });
  }
  return false;
});
 
});


//************************ Gallery menu ***/
$(function(){

var gallsList = {
  el: $('#galls-list'),
  list: $('ul','#galls-list')
}
gallsList.list.wrap('<div class="holder" />');
gallsList.el.find('.holder').data('origHeight',parseInt(gallsList.el.find('.holder').css('height')));
if ( gallsList.list.outerHeight(true) > gallsList.el.find('.holder').outerHeight(true) ) {
  gallsList.el.append('<div class="ctrls"><div><a class="expand">'+phrasebook.chooser+'</a></div></div>');
}
gallsList.el.find('.ctrls .expand').toggle(function(){
  gallsList.el.find('.holder').animate({ 'height': gallsList.list.outerHeight(true) });
}, function(){
  gallsList.el.find('.holder').animate({ 'height': gallsList.el.find('.holder').data('origHeight')});
});
 
});


//************************ Carousel ***/
$(function(){

var slider = {
  el: $('.info-alt-01','#item-gall'),
  item: $('.info-alt-01 ul','#item-gall')
}

slider.item.wrapAll('<div class="holder" />');
slider.item.first().addClass('visible');
slider.el.find('.holder').css({ 'width': slider.el.width()*slider.item.length })
slider.el.after('<div class="slider-ctrls"><a class="prev">Prev</a><a class="next">Next</a></div>');

$('.slider-ctrls a').click(function(){
  if ( $(this).hasClass('next') ){
    if ( slider.item.filter('.visible').nextAll().length === 0  ) {
      slider.el.find('.holder').animate({ 'margin-left': 0 }, function(){ slider.item.first().addClass('visible').siblings().removeClass('visible'); })
    } else {
      slider.el.find('.holder').animate({ 'margin-left': -(slider.item.filter('.visible').next().width()*slider.item.filter('.visible').next().index()) }, function(){ slider.item.filter('.visible').removeClass('visible').next().addClass('visible'); }); 
    }
  } else if ( $(this).hasClass('prev') ){
    if ( slider.item.filter('.visible').prevAll().length === 0  ) {
      slider.el.find('.holder').animate({ 'margin-left': -(slider.el.find('.holder').width()-slider.item.filter('.visible').width()) }, function(){ slider.item.last().addClass('visible').siblings().removeClass('visible'); })
    } else {
      slider.el.find('.holder').animate({ 'margin-left': -(slider.item.filter('.visible').prev().width()*slider.item.filter('.visible').prev().index()) }, function(){ slider.item.filter('.visible').removeClass('visible').prev().addClass('visible'); }); 
    }
  }
});
 
});


//************************ Form on submit check ***/
$(function(){
    $(".form-t01").submit(function(){
        $(this).find(".error").removeClass("error");
        $(this).find("label:has(em)").each(function(){
            if($(this).siblings('input').val()==""){ $(this).siblings('input').addClass("error"); }
        });        
        if($(this).find(".error").length!=0){ return false; }
    });
});


//************************ GMap ***/
$(function(){

  if ( $("#gmap").html()!=null ){
    var s = DGoogleMap2.displayMap("#gmap");
    DGoogleMap2.displayMarkers();
    DGoogleMap2.fitMapToMarkers();
  }
  
});



/**
* GOOGLE ANALYTICS FUNKCIJE
*/
var pageTracker_trackEvent_Kontakt_Poslano = function(){
	_gaq.push(['_trackEvent', 'Kontakt-obrazac', 'Kontakt-obrazac-Poslano']);
	if( typeof console != 'undefined' && console ) console.log("_trackEvent( 'Kontakt-obrazac', 'Kontakt-obrazac-Poslano' )");
};
var pageTracker_trackEvent_UpitZaModel_Poslano = function( event, model ){ 
	model = ( typeof event != 'undefined' && typeof event.data != 'undefined' && typeof event.data.model != 'undefined' ) ? event.data.model : model;
	_gaq.push(['_trackEvent', 'UpitZaModel', 'UpitZaModel-Poslano', model]);
	if( typeof console != 'undefined' && console ) console.log("_trackEvent( 'UpitZaModel', 'UpitZaModel-Poslano', '"+model+"' )");
};
