function disp_not_dsp(elemid,topelement,num) {	
    if (num==1) {
        document.getElementById(elemid).className = 'dsplblock';
		document.getElementById(topelement).className = 'specialoffert curentpagesp';
     }else{
        document.getElementById(elemid).className = 'dsplnone';
		document.getElementById(topelement).className = 'specialoffert';
    }
}
if(window.location.hostname=='localhost'){dir='http://localhost/ivis.bg/site/'}else{dir='http://www.ivis.bg/'}
//IMAGE POPUP
function pop_ivis(pURL, pWidth, pHeight) {
  if (!pURL) {
    return;
  }
  var offsetWidth = 50;
  var offsetHeight = 70;
  var windowFeatures = "toolbar=no,directories=no,location=no,status=no,menubar=no,resizable=yes,scrollbars=yes,"
    + "width=" + (pWidth + offsetWidth) + ",height=" + (pHeight + offsetHeight);
  var popup = window.open(pURL, 'imagePopup', windowFeatures);
  if (popup) {
    popup.focus();
	popup.moveTo(0,0);
  }
}
//END IMAGE POPUP
function rate(n) {
    for(var i=1; i<=5; i++) {
        var el = document.getElementById('rate'+i);
        if (i<n) el.innerHTML='<img onmouseover="rate('+i+');" src="'+dir+'images/blank.gif" style="background:url('+dir+'images/full_star.gif) center no-repeat;" alt="Rate '+i+'" width="18" height="16" />';
        else if (i==n) el.innerHTML='<img src="'+dir+'images/blank.gif" style="background:url('+dir+'images/full_star.gif) center no-repeat;" alt="Rate '+i+'" width="18" height="16" />';
        else  el.innerHTML='<img onmouseover="rate('+i+');" src="'+dir+'images/blank.gif" style="background:url('+dir+'images/empty_star.gif) center no-repeat;" alt="Rate '+i+'" width="18" height="16" />';
    }
}
var pos_1g=1;
var pos_2g=1;
function relFX(group,type,max){
   if(group==1){box='#rel1_box';pos=pos_1g;startpos=pos_1g;}
   else{box='#rel2_box';pos=pos_2g;startpos=pos_2g;}
   if(type==1){
        if((pos)==max){pos=1;}
        else{pos++;}
   }
   else{
        if((pos-1)==0){pos=max;}
        else{pos--;}
   }
   $(box+startpos).fadeOut('fast',function(){
   $(box+pos).fadeIn('fast');
   });
   if(group==1){
       pos_1g=pos;
   }
   else{
       pos_2g=pos;
   }
}
function number_format(number,decimals,dec_point,thousands_sep){var n=number,c=isNaN(decimals=Math.abs(decimals))?2:decimals;var d=dec_point==undefined?".":dec_point;var t=thousands_sep==undefined?".":thousands_sep,s=n<0?"-":"";var i=parseInt(n=Math.abs(+n||0).toFixed(c))+"",j=(j=i.length)>3?j%3:0;return s+(j?i.substr(0,j)+t:"")+i.substr(j).replace(/(\d{3})(?=\d)/g,"$1"+t)+(c?d+Math.abs(n-i).toFixed(c).slice(2):"")}
function buyColor(prod_id,ver_id,img,price,title,currency,mess,total_mess,cart_mess){
   qty=$('#qty_'+ver_id).attr('value');
   version=ver_id;
   $.post(dir+"mod_cart.php", {action: 'add_prod',prod_id: prod_id, version: ver_id, quan: qty, echo:1},
   function(data) {
     if($('#cp_cart').is(':empty')){
         $('#cp_cart').html('<tr><td colspan="5"><h5>'+mess+'</h5></td></tr>');
     }
     row='<td class="ver_img"><img src="'+dir+'img_tools.php?img=products_images/version/'+img+'&amp;w=48&amp;h=48" class="fleft" /></td><td class="ver_tit">'+title+'<td class="ver_quan">X <span>'+qty+'</span></td><td class="ver_price"><span class="pink">'+number_format((price*qty),2)+'</span> '+currency+'</td><td><a onclick="delColor('+data+','+(price*qty)+');" class="fright del_color"></a></td>';
     if ($('#cp_row_'+data).length > 0){
         $('#cp_row_'+data).html(row);
     }
     else{
         $('#cp_cart').html($('#cp_cart').html()+'<tr class="cp_cart_row" id="cp_row_'+data+'">'+row+'</tr>');
     }
     updateTotal(total_mess,currency,cart_mess);
   });
}
function updateTotal(mess,currency,cart_mess){
   total=0;
   $('#cp_cart span.pink').each(function(){
       total+=parseFloat($(this).html());
   });
   if($('#tot_price').length==0){$('<div id="tot_price" class="price prprev_price fright">'+mess+': <b id="cp_total"></b> '+currency+'<div class="clear"></div><a onclick="parent.$.colorbox.close(\'cart.php\');" class="cp_cart_view fright"><span>'+cart_mess+'</span></a></div>').insertAfter('#cp_cart');}
   $('#cp_total').html(number_format(total,2));
}
function delColor(id,total){
   $.get(dir+"mod_cart.php", {dell: id},
   function(data) {
        $('#cp_row_'+id).remove();
        updateTotal('','','');
        if($('tr.cp_cart_row').length == 0){
            $('#cp_cart').html('');
            $('#tot_price').remove();
        }
   });
}
$(document).ready(function(){
var cur;
var done=1;
var parent;
var _init=0;
$('a.preview').each(function(){
    $([$(this).attr('rel')]).preload();
});
$([dir+'images/full_star.gif',dir+'images/empty_star.gif',dir+'images/preload.gif']).preload();
if(jQuery.isFunction(jQuery.colorbox)){
    $("a.colorPick").colorbox({width:"942", height:"542", iframe:true});
    $("a.old_orders").colorbox({width:"800", height:"500", iframe:true});
    $("a.img_prod").colorbox();
    $("a.video").colorbox({innerWidth:600, innerHeight:500, iframe:true});
}
if($('div.coda-slider').length>0){  
    $('div.coda-slider').codaSlider();
    $('div.gallery').css('visibility','visible');
}
if($('.nivo').length>0){
    $('.nivo').nivoSlider({
            effect:'random',
            slices:12,
            boxCols: 4,
            boxRows: 4,
            animSpeed:200,
            pauseTime:7000, // How long each slide will show
            startSlide:0,
            directionNav:true,
            directionNavHide:false,
            controlNav:true,
            controlNavThumbs:false,
            controlNavThumbsFromRel:false,
            keyboardNav:true, // Use left &amp; right arrows
            pauseOnHover:true, // Stop animation while hovering
            manualAdvance:false,
            captionOpacity:0.8,
            beforeChange: function(){$('a.nivo-imageLink').css('z-index','0');}, // Triggers before a slide transition
            afterChange: function(){$('a.nivo-imageLink').css('z-index','6');}, // Triggers after a slide transition
            slideshowEnd: function(){}, // Triggers after all slides have been shown
            lastSlide: function(){}, // Triggers when last slide is shown
            afterLoad: function(){} // Triggers when slider has loaded
    });
    $('div.nivo').removeClass('in_nivo loading');
}
$('.nextSlide').click(function(){
    if(done==1){
        done=0;
        parent=$(this).parents('div');
        if($(cur).length==0){
            cur=$(parent).children('a.shop_main_img').first();
        }
        else{
            cur=$(parent).children('a.cur').first();
        }
        next=$(cur).next('a.shop_main_img');
        if($(next).length!=0){
            $(cur).fadeOut('fast',function(){$(cur).removeClass('cur')
            $(next).fadeIn('fast',function(){$(next).addClass('cur');done=1;});
            });
        }
        else{
             $(cur).fadeOut('fast',function(){
                $(cur).removeClass('cur');
                $(parent).children('a.shop_main_img').first().fadeIn('fast',function(){$(parent).children('a.shop_main_img').first().addClass('cur');done=1;});
            });
        }
    }
});
$('.prevSlide').click(function(){
    if(done==1){
        done=0;
        parent=$(this).parents('div');
        if($(cur).length==0){
            cur=$(parent).children('a.shop_main_img').first();
        }
        else{
            cur=$(parent).children('a.cur').first();
        }
        next=$(cur).prev('a.shop_main_img');
        if($(next).length!=0){
            $(cur).fadeOut('fast',function(){
                $(cur).removeClass('cur');
                $(next).fadeIn('fast',function(){$(next).addClass('cur');done=1;});
            });
        }
        else{
            $(cur).fadeOut('fast',function(){
                $(cur).removeClass('cur');
                $(parent).children('a.shop_main_img').last().fadeIn('fast',function(){$(parent).children('a.shop_main_img').last().addClass('cur');done=1;});
            });
        }
    }
    });
    $('div.expander').mouseenter(function(){
        _el=$(this).children('span.exp_but');
        if(_el.length>0){
            _el.css('display','block');
        }
    });
     $('div.expander').mouseleave(function(){
        _el=$(this).children('span.exp_but');
        if(_el.length>0){
            _el.css('display','none');
        }
    });
    $('span.exp_but').click(function(){
        _me=$(this);
       _el=$(this).parent('div').children('div.prod_container');
       if(!_el.hasClass('expanded')){
           _h=_el.children('div.special_box').height()+10; 
           _el.animate({height: _h+'px'},function(){
               $(this).addClass('expanded');
               _me.css('background-position','0px 0px');
           });
       }
       else{
           _el.animate({height: '95px'},function(){
               $(this).removeClass('expanded');
               _me.css('background-position','0px -15px');
           });
       }
    });
    $('div.fakes a.closeMe').click(function(){
       $('div.fakes').slideUp('fast'); 
       $.post(dir+'ivisAjax.php', {hide_fakes:1}, function(data){
           // nothing
       });
    });
    $('img.baloon').mouseenter(function(){
       _y=$(this).offset().top;
       _x=$(this).offset().left
       _img=$(this).attr('title');
       if(_img!=''){
           $('#baloon_cont img').attr('src',dir+'products_images/version/'+_img);
           $('#baloon_cont').css({left: _x/2-10+'px', top: _y/2-10+'px', display: 'block'});
       }
    });
    $('img.baloon').mouseleave(function(){
           $('#baloon_cont').css('display','none');
    });
    
    if($('#facebookHolder').length>0){
       $('#facebookHolder').html('<fb:like href="" send="false" layout="button_count" width="200" show_faces="false" action="recommend" font="verdana"></fb:like>');  
       window.___gcfg = {lang: 'bg'};
       jQuery.getScript('https://apis.google.com/js/plusone.js');
       jQuery.getScript('http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4e294fe529126620');
       _init=1;
    }
    if($('#right_facebook').length>0){
       $('#right_facebook').html('<fb:like-box href="http://www.facebook.com/pages/IVISBG-OFFICIAL/207806399240631" width="180" height="305" show_faces="true" border_color="#ffffff" stream="false" header="false"></fb:like-box>');
       _init=1;
    }
    if(_init==1){
       jQuery.getScript('http://connect.facebook.net/bg_BG/all.js#xfbml=1', function() { 
           FB.init({status: true, cookie: true, xfbml: true}); 
           fbInit=true;
       }); 
    } 
});
function fbCallback(callback) {
    if(!window.fbInit) {
        setTimeout(function() {fbCallback(callback);}, 50);
    } else {
        if(callback) {
            callback();
        }
    }
}
fbCallback(function() {
    $('#right_facebook').removeClass('loading');
});
function addline(val){
    if(val!=''){
        $.post(dir+'getlines.php', {mark_id: val}, function(data){
        $('#line_id').css('display','none');
        $('#line_select').html(data);
        $('#line_id').css('display','table-row');
        });
    }
    else{
        $('#line_id').css('display','none');
    }
}
$.fn.preload = function(){this.each(function(){$('<img/>')[0].src = this;});}
