
//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}

//clear value
function ci(elem){
		elem.value = '';
}


$(document).ready(function() {
  
   // add js to body for css
   $(document.body).addClass('js')
   if(jQuery.browser.safari) $(document.body).addClass('safari')


  /*Jump menu function for dropdowns*/
  $('.jump_menu').bind('change', function(){
    window.location.href = $(this).val();
  });
  
   // Vertical menu brands
   var acc_last = {};
  

  
  // if IE 6 
 	if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
    $('span.btn').hover(function(){$(this).addClass('btn_hover')},function(){$(this).removeClass('btn_hover')})  
    $('.tt_3 td').hover(function(){$(this).closest('.tt_nav').addClass('tt_3_hover')},function(){$(this).closest('.tt_nav').removeClass('tt_3_hover')})   
    $('.tt_2 td').hover(function(){$(this).closest('.tt_nav').addClass('tt_2_hover')},function(){$(this).closest('.tt_nav').removeClass('tt_2_hover')})   
    $('.package .options').hover(function(){$('select').css('visibility','hidden')},function(){$('select').css('visibility','visible')})
   
    //IE6 alpha
    if($e(".special-box h2, .attribute-desc .attribute-icon")) $ee.pngFix({method:'crop'});
  }
  
  
  // Left menu collapsing 
   $('.special-collapse .collapse ul').hide()
   acc_last['ul'] = $('.special-collapse .collapse-open ul')
   acc_last['h2'] = acc_last['ul'].parent().addClass('collapse-open').find('h2')
   acc_last['ul'].show("blind",null,"fast");

   function specialCollapse(){
    if(acc_last['h2'] != this){
       if (acc_last['h2']) $(acc_last['h2']).parent().removeClass('collapse-open')
       if (acc_last['ul']) acc_last['ul'].hide("blind",null,"fast");
      
       acc_last['h2'] = this
       
       $(this).parent().addClass('collapse-open')
       acc_last['ul'] = $(this).parent().find('ul').show("blind",null,"fast");
     }
   }
   
	var hoverIntentConfig = {    
		sensitivity: 3,
		interval: 200,
		over: specialCollapse,
		timeout: 500,
		out: function(){}
	}; 
	
	$('.special-collapse.special-collapse-has-items .collapse h2').hoverIntent(hoverIntentConfig); 
   
  //Table classes 
  $('tr:odd').addClass('odd')
  $('tr:first-child').addClass('first')
  $('tr:last-child').addClass('last')
  $('tr:even').addClass('even')
  $('tr > td:first-child, tr > th:first-child').addClass('first')
  $('tr > td:last-child,  tr > th:last-child').addClass('last')
  $('tr').each(function(index, row){  
    n=0;
    $(row).find('td, th').each(function(i, cell){      
      if(!$(cell).attr("class")) $(cell).addClass('col'+(++n))
    })   
  })
  
  //package
  $('.packages .package .body p:last-child, .packages .package .bubble p:last-child').addClass('lastone')
  $('.packages .package:nth-child(3n-2)').addClass('first-package-in-row')
 
  
  
  //specialboxes equal height  
 // if($e('.height_group .special-box .in2')) $ee.equalizeCols()
  
//  if($e('.packages .package .body')) $ee.equalizeCols()

  if($e('.height_group')) $ee.each(function(i,g){
    $(g).find('.box-in').equalizeCols()
    $(g).find('.package .body').equalizeCols()
    $(g).find('.box-in, .package').equalizeCols()
    $(g).find('.special-box .in2').equalizeCols()
  })
  
  if($e('.ec')) $ee.equalizeCols(null, true, 14)
  

  
  
  //Za kuću
  if($e('#tabbed_teaser .tt_tabs')){
    $ee.cycle({
        fx:     'fade',
        speed:  'fast',
        timeout: 0,
        pager:  '#tabbed_teaser .tt_nav',
        pagerEvent: 'click',
        pagerAnchorBuilder: function(idx, slide) {
            return '#tabbed_teaser .tt_nav td.handle_' + idx;
        }
    });    
  }
  


  //Select + gumb => go to url
  $('.trazilica input.btn').click(function(){
   window.location.href = $(this).parents('td.trazilica').find('select').val();
  })    
  
 
  //Packages Bubbles 
  $('.package .options').hover(
    function(){     
      $(this).addClass('options-hover')
    },function(){
     $(this).removeClass('options-hover')
   })
 

  

 });
