$(document).ready( function () {    
        $('#countries-toggle').toggle( function () {
                $('#countries').stop().animate({'height': $('#countries .outside').height() }, 700, 'easeOutExpo');
                return false;
        }, function () {
                $('#countries').stop().animate({'height': 0 }, 700, 'easeOutExpo');
                return false;
        }).disableTextSelect();
        
        $('#countries-close').click( function () {
                $('#countries-toggle').trigger('click');
                return false;
        });
        
/*tabs*/
$('.tabs a').click( function () {
  $(this).parents('.tabs').find('td').removeClass('current');
  $(this).parents('td').addClass('current');            
  var ids = '';
  $(this).parents('.tabs').find('a').each( function () {
    ids += '#'+$(this).attr('name')+',';
  });
  $(ids).addClass('hidden');
  $('#'+$(this).attr('name')).removeClass('hidden');
  return false;
});

var id = $.frequency($("#promo").data("impression"));
$.promo(id);

$('.more-options,.close_').click(function () {
$(this).parents('.ns_').find('.modal').toggleClass('hidden');
return false;
});


/*scroll logo*/                         
$('.next_').click( function () {
$('.scrollable_').scrollTo('+=592px', 1000);                            
});
$('.prev_').click( function () {
$('.scrollable_').scrollTo('-=592px', 1000);                            
});     


/*show flash chooser in popup*/
$('.flashalert').click( function () {
var id = $(this).attr('name');
$(window).htmlPopup({
'opacity':'0.65',
'width': $('#'+id).data('width'),
'duration': 300,
'top': $('#'+id).data('top'),
'html': $('#'+id).html()
});
return false;
});

/*scroll page*/
$("<a name='top'></a>").prependTo("body");
$('.top, .banners, .prodbox').localScroll();
$('.top a, .banners a').click(function () { 
return false;
});

/*fix bug with collapsed +-*/
if(!$.browser.msie){
var objects_ = $('a[onclick^=value]');  
var pattern1 = /(value.*?;)/g;  
$(objects_).click( function () {
var onclick_ = $(this).attr('onclick').toString();                      
var result1 = onclick_.match(pattern1);
if (result1 != null){
for ( i in [result1[0], result1[1]] ){
//alert(result1[i]);
var pattern2 = /(value.*?\.)/;
var result2 = result1[i].match(pattern2);
var s = result1[i].search(/none/);
if(s != '-1'){
$('#'+result2[i].slice(0, -1)).css('display', 'none');
//$(result2[i]).css('display', 'none');
}
else{
$('#'+result2[i].slice(0, -1)).css('display', '');
}
}                                               
}               
return false;
});
}

/*trigger for tabs*/
$('.trigger_').click( function (){
$('a[name='+$(this).attr('name')+']:not(.trigger_)').trigger('click');
window.scrollTo(0,$("#"+$(this).attr('name')).offset().top);
return false;
});


/*prettyPhoto*/
$("head").append('<link rel="stylesheet" href="downloads/pp/prettyphoto.css" type="text/css" media="screen" title="prettyPhoto main stylesheet" charset="utf-8" />');
$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});


/* Open popup if "htmlPopup_site" is defined */
if(typeof htmlPopup_site == "string")
{
 var width; (typeof htmlPopup_width != "undefined") ? width=htmlPopup_width : width=683;
 openHtmlPopup(htmlPopup_site,width);
}

/* Bind htmlPopup to link */
$(".htmlPopup").click(function (event){
 event.preventDefault();
 var width=660;
 var url = $(this).attr("name");
 if(url.indexOf("?width=") != -1){
  width = url.substring(url.indexOf("?width=")+7);
  url = url.substring(0, url.indexOf("?width="));
 }
 openHtmlPopup(url,width);
});

/*Renew tabs*/
$('.sections li').click( function () {
$('.sections li').removeClass('current');
$(this).addClass('current');
$('.section').addClass('hidden');
$('#'+$(this).find('a').attr('name')).removeClass('hidden');
$('#'+$(this).find('a').attr('name')+'_').removeClass('hidden');
return false;
});


      if($('#socialshareprivacy').length > 0){
        $('#socialshareprivacy').socialSharePrivacy(); 
      }


});
