/**
 * @author POC
 */
$(document).ready(function(){


//    var timp_efect = 600;
//    var ascunde0, ascunde1, ascunde2
//    //creez id-uri
//    $(".meniu").each(function(i){
//        $(this).attr("id", "meniu-" + i)
//    });
//    $(".menu-item").each(function(i){
//        $(this).attr("id", "meniu-item-" + i);
//    });
//    $(".menu-item-link").each(function(i){
//        $(this).attr("id", "menu-item-link-" + i);
//    });
//    $(".btntext img").each(function(i){
//        $(this).attr("meniu", i);
//    });
//    $(".submenu").each(function(i){
//        $(this).attr("id", "meniu-item-sub-" + i);
//        $(this).find(".submencontainer").attr("id", "meniu-item-sub-container-" + i);
//        $(this).find(".submenu-item").each(function(k){
//            $(this).attr("id", "submenu-" + i + "-item-" + k);
//        });
//    });
//    
//    
//    ////////////////////////////
//    $(".submenu-item").after('<div class="submenu-spacer"><img src="./images/transparent.gif" width="1" height="1" /></div>');
//    $(".links-link").after('<div class="links-separator"><img src="./images/transparent.gif" width="1" height="1" /></div>');
//    
//    $(".submenu-item, .menu-item-link").hover(function(){
//        $(this).css("text-decoration", "underline");
//    }, function(){
//        $(this).css("text-decoration", "none");
//    });
//    
//    
//    ////////// ascuns meniuri
//    $(".btntext img").mouseenter(function(){
//        var meniu = "#meniu-" + $(this).attr("meniu");
//        var menid = "" + $(this).attr("meniu")
//        switch (menid) {
//            case "0":
//                clearTimeout(ascunde0)
//                break;
//            case "1":
//                clearTimeout(ascunde1)
//                break;
//            case "2":
//                clearTimeout(ascunde2)
//                break;
//        }
//        
//        $(meniu).fadeIn('fast');
//        
//        
//    }).mouseleave(function(){
//        var meniu = "#meniu-" + $(this).attr("meniu");
//        var menid = "" + $(this).attr("meniu")
//        switch (menid) {
//            case "0":
//                ascunde0 = setTimeout("$('" + meniu + "').fadeOut()", 300);
//                break;
//            case "1":
//                ascunde1 = setTimeout("$('" + meniu + "').fadeOut()", 300);
//                break;
//            case "2":
//                ascunde2 = setTimeout("$('" + meniu + "').fadeOut()", 300);
//                break;
//        }
//        
//        
//    });
//    
//    
//    
//    $(".meniu").mouseenter(function(){
//        var meniu_id = $(this).attr("id");
//        var mennr = "" + meniu_id.substring(6)
//        switch (mennr) {
//            case "0":
//                clearTimeout(ascunde0)
//                break;
//            case "1":
//                clearTimeout(ascunde1)
//                break;
//            case "2":
//                clearTimeout(ascunde2)
//                break;
//                
//        }
//        
//    }).mouseleave(function(){
//        var meniu_id = $(this).attr("id");
//        var mennr = "" + meniu_id.substring(6)
//        switch (mennr) {
//            case "0":
//                ascunde0 = setTimeout("$('#" + meniu_id + "').fadeOut()", 300);
//                break;
//            case "1":
//                ascunde1 = setTimeout("$('#" + meniu_id + "').fadeOut()", 300);
//                break;
//            case "2":
//                ascunde2 = setTimeout("$('#" + meniu_id + "').fadeOut()", 300);
//                break;
//        }
//        
//    });
//    
//    
//    ////////// 
//    $(".menu-item").each(function(i){
//        $(this).css("cursor", "pointer");
//        
//        if ($("#meniu-item-sub-" + i).length > 0) 
//            $(this).css("background", "#4e7e1f url('./images/submenu_expand.gif') 8px 50% no-repeat");
//        
//        $(this).bind("click", function(e){
//        
//        
//            $(".submenu").each(function(k){
//            
//                if (k != i) {
//                    $("#meniu-item-" + k).css("background", "#4e7e1f url('./images/submenu_expand.gif') 8px 50% no-repeat");
//                    $(this).animate({
//                        opacity: 0,
//                        height: 0
//                    }, timp_efect);
//                }
//            });
//            
//            
//            
//            var c = 0;
//            var f = $("#meniu-item-sub-container-" + i).innerHeight() + 10;
//            
//            if ($(this).css("background-image").indexOf('submenu_expand.gif') > -1) {
//                $(this).css("background", "#4e7e1f url('./images/submenu_colapse.gif') 8px 50% no-repeat");
//                
//                $("#meniu-item-sub-" + i).animate({
//                    height: f,
//                    opacity: 1
//                }, timp_efect);
//                
//                c = 1;
//            }
//            if ($(this).css("background-image").indexOf('submenu_colapse.gif') > -1 && c == 0) {
//                $(this).css("background", "#4e7e1f url('./images/submenu_expand.gif') 8px 50% no-repeat");
//                $("#meniu-item-sub-" + i).animate({
//                    opacity: 0,
//                    height: 0
//                }, timp_efect);
//                
//            }
//            
//        });//sfarsit click submeniu
//    });
//    
//    $(".menu-item-link").bind("click", function(e){
//        $(".submenu").each(function(k){
//            var f = $("#meniu-item-sub-container-" + k).innerHeight();
//            if (f > 0) {
//                $("#meniu-item-" + k).css("background", "#4e7e1f url('./images/submenu_expand.gif') 8px 50% no-repeat");
//                $(this).animate({
//                    opacity: 0,
//                    height: 0
//                }, timp_efect);
//            }
//        });
//    });
//    
//    ////////////////////	
//    $('.header-pic').cycle({
//        fx: 'fade',
//        speed: 1500,
//        timeout: 30000
//    });
//    //DD_belatedPNG.fix('.header-top , .header-btm, .logo');
//    ///////////Contact
    
    $(".panel-buton").each(function(i){
        var buton = $(this);
        var panou = $(this).parents(".centre:first");
        var PanouDetalii = panou.find(".panel-content-container");
        var InaltimeContinut = PanouDetalii.find(".panel-content-details").height();
        buton.click(function(){
            var InaltimePanouDetalii = PanouDetalii.height();
            if (InaltimePanouDetalii > 11) {
                PanouDetalii.stop().animate({
                    height: 10
                }, 500);
				$(this).css({'background-image':"url(http://audiooptica.contentspeed.ro/cs-images/contact/contact_plus.gif)"});
            }
            else {
                PanouDetalii.stop().animate({
                    height: InaltimeContinut + 10
                }, 500);
				$(this).css({'background-image':"url(http://audiooptica.contentspeed.ro/cs-images/contact/contact_minus.gif)"});
            }
            
        })
        
    });
    
});


function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}


function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}


















