jQuery(document).ready(function(){
	jQuery("a.fancybox").fancybox();
	jQuery(".postImg img").removeAttr('title');

    var fancybox_iframe = jQuery('li.modal a');
    if (fancybox_iframe.length > 0){
        fancybox_iframe.each(function(index){
			var rel = jQuery(this).attr('rel');
            // Inline frame width param
            if( rel && rel.match(/width[0-9]+/i) ){
                var fWidth = parseInt(jQuery(this).attr('rel').match(/width[0-9]+/i)[0].replace('width',''));
            } else {
                var fWidth = 510;
            }
            // Inline frame height param
            if(  rel && rel.match(/height[0-9]+/i) ){
                var fHeight = parseInt(jQuery(this).attr('rel').match(/height[0-9]+/i)[0].replace('height',''));
            } else {
                var fHeight = 550;
            }
            if(window.console&&window.console.log) {
                console.log('fWidth #'+index+': '+fWidth);
                console.log('fHeight #'+index+': '+fHeight);
            }
            jQuery(this).fancybox({
                padding : '0',
                type : 'iframe',
        		titlePosition : 'outside',
        		transitionIn : 'none',
        		transitionOut : 'none',
        		autoDimensions: false,
        		autoScale: false,
        		width: fWidth,
        		height: fHeight
        	});
        });
    }
    var target = jQuery("#target");

    target
    .children('div')
    .parallax(
      { yparallax: false },      // Options
      { xparallax: '45px' },      // Layer 1
      { xparallax: '45px' },     // Layer 2
      { xparallax: '90px' },     // Layer 3
      { xparallax: '80px' },     // Layer 4
      { xparallax: '100px' },     // Layer 5
      { xparallax: '90px' },    // Layer 6
      { xparallax: '50px' }     // Layer 7
    );
    jQuery('#logo img').hover(function(){
      jQuery(this).stop().animate({opacity:0},200);
    },function(){
      jQuery(this).stop().animate({opacity:1},200);
    });
    jQuery('.button .bl .hover').prepend('<ins class="bh"><b class="bhr"><i class="bhl"></i></b></ins>').css({opacity:0});
    jQuery('.button').hover(function(){
      jQuery('.hover',this).stop().animate({opacity:1},200);
    },function(){
      jQuery('.hover',this).stop().animate({opacity:0},200);
    });

    var sb_w = 221;
    jQuery('.sidebar-xoxo').appendTo('#sidebar').each(function(){
        var sb_w0 = jQuery(this).attr('data-width');
        if(sb_w0) {
          if(sb_w0 > sb_w)
              sb_w = sb_w0;
          var c_w = 810 - sb_w;
          jQuery('#content').css('width',c_w);
          jQuery('#sidebar').css('width',sb_w);
        }
    }).slideDown('fast');

    jQuery('span.more-button').click(function(){
      jQuery(this).prev('.more-content').slideToggle().parent().toggleClass('yay');
    });

    jQuery('#modal .phone input').bind('focus mouseup', function(){
      if(!jQuery(this).val())
        jQuery(this).val('+380');
    });
    jQuery('#modal .phone input').bind('blur', function(){
      if(jQuery(this).val() == jQuery(this).attr('title'))
        jQuery(this).val('');
    });
    jQuery('#modal .call_am select').val('9');
    jQuery('#modal .call_pm select').val('19');
    jQuery('#modal #refferer').val(document.referrer);
    jQuery('#modal #usluga option[value="---"]').text("- Выбирите услугу -");
    jQuery('#modal .wpcf7-submit').click(function(){
      jQuery(this).parents('form').find('.inp').removeClass('error');
    });
    jQuery('.wpcf7-not-valid-tip').live('mouseover',function(){
      jQuery(this).parent().parent().addClass('error');
    });
    jQuery('#modal #usluga').each(function(){
        var usluga = jQuery(parent.document).find('h1.entry-title').text();
        //console.log(usluga);
        if(jQuery('option[value='+usluga+']',this))
            jQuery(this).val(usluga);
    });

});

