/*
 * DigiStyle 1.5 jQuery Functions
 * Created by UWiX - Copyright 2010 - All Rights Reserved
 *
 */
  
(function($){

  $.fn.removeCss = function(cssName) { // Remove CSS style from an element
    return this.each(function() {
        var curDom = $(this);
        jQuery.grep(cssName.split(","),
                function(cssToBeRemoved) {
                    curDom.css(cssToBeRemoved, '');
                });
        return curDom;
    });
  }

  $.fn.setFBox = function( option ) {
    var opt = $.extend ({
      options: {},
      thewidth: 560,
      theheight: 340,
      overlaycolor: '#666',
      showoverlay: 'true',
      overlayopacity: 0.3,
      fbmargin: 20,
      fbpadding: 10
    }, (option||{}));
    
    return this.fancybox( {
      "width": parseInt(opt.thewidth),
      "height": parseInt(opt.theheight),
      "autoScale": false,
      "showNavArrows": false,
      "titleShow": false,
      "overlayColor": opt.overlaycolor,
      "overlayShow": opt.showoverlay,
      "overlayOpacity": opt.overlayopacity,
      "margin": parseInt(opt.fbmargin),
      "padding": parseInt(opt.fbpadding),
      "type": "swf"
     });
   };


  /* Created by UWiX */
  $.fn.prepDSImage = function( cname ) {
    var xstyle = '';

    if (($.browser.msie)) {
      if (cname == 'flatC') {
        xstyle = 'width: '+this.outerWidth(true)+'px;';
      } else {
        xstyle = 'width: '+(this.outerWidth(true)+16)+'px;';
      }
    };
    
    return this.wrap("<div class='"+cname+"' style='"+xstyle+"'></div>");
  };
  
  /* Created by UWiX */
  $.fn.setDSReflex = function( reflectH, reflectO ) {
    return this.reflect( {
      height: reflectH,
      opacity: reflectO
    } );
  };
  
  /* Created by UWiX */
  $.fn.setDSShadowBox = function( dsleft, dstop, dsblur, dsopacity, dscolor ) {
    return this.dropShadow( {
      left: dsleft,
      top: dstop,
      blur: dsblur,
      opacity: dsopacity,
      color: '"'+dscolor+'"'
    } );
  };

  /* Created by UWiX */
  $.fn.DSFade = function (option) {
    var opt = $.extend ({
      options: {},
      duration: 500,
      opacity_start: 0.2,
      opacity_end: 1
    }, (option||{}));
    return this.hide().fadeTo(1, opt.opacity_start).show()
       .hover(function() { $(this).stop().animate({"opacity": opt.opacity_end}, opt.duration); },
              function() { $(this).stop().animate({"opacity": opt.opacity_start}, opt.duration); });
  }

  /* Created by UWiX */
  $.fn.DSGrow = function (option) {
		var opt = $.extend({
			options: {},
			duration: 500,
			multiply: 1.2,
			callback: null
		}, (option||{}));

    var e = $(this);
		var currpos = e.offset();
    var currW = e.width();
    var currH = e.height();
    var posL = ((currW * opt.multiply) - currW) / 2;
    var posT = ((currH * opt.multiply) - currH) / 2;
    var ecl = e.clone();
    var isurl = e.parents().attr("href");
    
    ecl.attr('style', '');
	  ecl.css({
			left: currpos.left,
			top:  currpos.top,
			position: "absolute"
		}).appendTo(document.body);

		if (isurl != null) {
			ecl.css({
        cursor: "pointer"
			}).appendTo(document.body);
    }
    
    ecl.hover(function() {
              $(this).stop()
               .animate({
                 width: (currW * opt.multiply) +'px',
                 height: (currH * opt.multiply) +'px',
                 left: (currpos.left - posL)+'px',
                 top:  (currpos.top - posT)+'px'
                }, opt.duration); },
            function() { $(this).stop()
               .animate({
                 width: currW+'px',
                 height: currH+'px',
                 left: (currpos.left)+'px',
                 top:  (currpos.top)+'px'
               }, opt.duration, function() {
                   if(opt.callback){opt.callback.apply(e);}
                 }
               );
    });
    
    if (isurl != null) {
      ecl.click(function() { window.location=isurl });
    }

    return false;
  }
  
  /* Created by UWiX */
  $.fn.dsmovie = function () {
    var subb = $(this).find('img.dsmovie').attr('class').split(' ');
    var fw = 0; var fh = 0;
    $.each(subb, function(index, value){
      if(subb[index].match( /^width:\d+$/ )) {
        fw = subb[index].split( ':' )[1];
      } else
      if(subb[index].match( /^height:\d+$/ )) {
        fh = subb[index].split( ':' )[1];
      }
    });
    var myarray = [fw, fh];
    return myarray;
  }

})(jQuery);
