/*
** This was created by Ujeen
*/

/*  --==:: Banner Blik Animation ::==--  */
$(document).ready(function(){

  if(!$.browser.msie){
    $('.for_blick').css('position','relative');

    $('.for_blick').each(function(item){
      var link = $(this).children('a');
      var href = link.attr('href');
      var a_height;
      var a_width;
      a_height = link.innerHeight();
      a_width = link.innerWidth();

      $(this).children('a').children().each(function(){
        if (this.tagName == 'IMG') {
          a_height = $(this).height();
          a_width = $(this).width();
        }
      })
      var target = '_self';
      var speed = 150;
      var offset = 100;
      var pad = 2;
      if ($(this).children('a').attr('target')) {
        target = $(this).children('a').attr('target');
      }
      var button;
      button = '<a class="blick iePNG" href='+href+' target='+target+'></a>';
      $(this).append(button);
      var blik = $(this).children('a.blick');
      var blik_css = {
        'position':'absolute',
        'left':pad,
        'top':'0px',
        'height':a_height,
        'width':(a_width-(pad*2)),
        'display':'block',
        'zindex':'1000',
        'background':'url("theme/images/blik.png") no-repeat -'+offset+'px top',
        'opacity':0.8
      }
      blik.css(blik_css);
      var anim_width = a_width;
      blik.mouseover(function(){
        $(this).stop();
        $(this)
        .animate({
          backgroundPosition:'('+(anim_width+offset)+'px 0px)'
        },speed)

      });
      blik.mouseout(function(){
        $(this).stop();
        $(this)
        .animate({
          backgroundPosition:'(-'+offset+'px 0px)'
        },speed)
      });
    })



  }
});

/* --==:: Search Box Animation ::==-- */
$(function(){
  $(document).ready(function(){


    var l_w = $('.loupe').width();
    var l_h = $('.loupe').height();
    var lb_w = $('.loupebox').width();
    var lb_h = $('.loupebox').height();
    var l_left = (lb_w-l_w)/2;
    var l_top = (lb_h-l_h)/2;


    $('.loupebox').css({
      width:lb_w,
      height:lb_h,
      textAlign:'left',
      verticalAlign:'top'
    })
    $('.loupe').css({
      margin:0,
      marginLeft:l_left,
      marginTop:l_top,
      padding:0
    });
    var action = 1;
    var stoped = false;
    var loupe = $('.loupe').eq(0);

    $('.custom-box-1').mouseover(function (){
      function amimate_loupe() {
        if (action == 0) {
          //console.log(circle);
          loupe
          .animate({
            marginTop:(l_top-4),
            marginLeft:(l_left-4)
          },400)
          .animate({
            marginTop:(l_top+4)
          },400)
          .animate({
            marginLeft:(l_left+4)
          },400)
          .animate({
            marginTop:(l_top-4)
          },400)
          .animate({
            marginTop:(l_top-4),
            marginLeft:(l_left-4)
          },400)
          .animate({
            marginTop:(l_top+4)
          },400)
          .animate({
            marginLeft:(l_left+4)
          },400)
          .animate({
            marginTop:(l_top-4)
          },400)
          .animate({
            marginTop:(l_top),
            marginLeft:(l_left)
          },400);
        }
      }
      if (action == 1) {
        action = 0;
        stoped = false;
        amimate_loupe();
      }
    //console.log(action)
    });
    $('.templates_box, .header, .left, .text_block').mouseover(function (e){
      action = 1;
      //if (!stoped) {
      loupe.stop()
      .animate({
        marginTop:(l_top),
        marginLeft:(l_left)
      },400);
    //stoped = true;
    //}
    })
    $('.custom-box-1 option').mouseover(function (e){
      loupe.stop()
      if (!stoped) {
        loupe.stop()
        .animate({
          marginTop:(l_top),
          marginLeft:(l_left)
        },400);
        stoped = true;
      }
    })

  })
});

/*  --==:: Slide Background ::==-- */
$(document).ready(function(){
  if(!($.browser.msie && ($.browser.version == '6.0'))) {
    $('#header').css({
      'background-position': 'left +158px'
    });
    $('#content .content_topbg').css({
      'background-position': 'left -219px'
    });
    $.timer(1500, function (timer) {
      $('#header').animate({
        backgroundPosition: '(0 -23px)'
      },300)
      timer.stop();
    });
    $.timer(2000, function (timer) {
      $('#content .content_topbg').animate({
        backgroundPosition: '(0 -19px)'
      },300)
      timer.stop();

    });

  }
});



