/*
 *
 *  author: Damian Ignacio Valdes.
 *  email: damian.ignacio@gmail.com
 *  date first relase: Wed May 19, 8:15 AM
 *  REcontraBETA
 *
 * */



/*(function($) {

$.fn.extend({

    imageRotator: function() {

        var imagesObj = [];
        var $imagesUrl = [];
        var $imagesContainer = [];
        var currentImage = 0;
        var currentContainer = 0;


        var defaults = {};

        var options = $.extend(defaults, options);

        var self = this;        

        $imagesContainer = $(".image_rotator_inner",self);

        $imagesUrl = $("#images_buffer .url",self);

        $imagesUrl.each(function(i,obj){

            $img = $('<img />').attr('src',$(obj).html());
            if($img.attr('complete')){
                imagesObj[i] = $img;
                return true;
            }

            $img.load(function(){
                imagesObj[i] = $(this);
            });

            return true;
        });

        _init();




        function _init(){       
            
            if(imagesObj && imagesObj && imagesObj.length != $imagesUrl.length){
                setTimeout(_init, 500);
                return;
            }
            _toggleImage();

        }

        function  _toggleImage(){           

            currentImage = currentImage%imagesObj.length;
            currentContainer = currentContainer%2;

                $($imagesContainer[(currentContainer + 1)%2]).css('z-index',0);
                $($imagesContainer[currentContainer])
                    .html(imagesObj[currentImage])
                    .css('z-index',99).fadeIn(1000,function(){
                        $($imagesContainer[(currentContainer + 1)%2]).hide();
                        currentImage++;
                        currentContainer++;
                        setTimeout(_toggleImage, 5000);
                    });

        }
    } 
});

})(jQuery); */

(function($) {

$.fn.extend({

    imageRotator: function() {

        var imagesObj = [];
        var $imagesUrl = [];
        var $imagesContainer = [];
        var currentImage = 0;
        var currentContainer = 0;


        var defaults = {};

        var options = $.extend(defaults, options);

        var self = this;

        $imagesContainer = $(".image_rotator_inner",self);

        $imagesUrl = $("#images_buffer img",self);

        _init();



        /***********/
        /* PRIVATE */
        /***********/

        function _init(){

            var i = 0;

            $imagesUrl.imgpreload(
                {
                    each: function(){
                        imagesObj[i] = this;
                        i++;
                    },
                    all: function(){
                        _toggleImage();
                    }
                }
            );
        }

        function  _toggleImage(){

            if(imagesObj.length > 0){
                currentImage = currentImage%imagesObj.length;
                currentContainer = currentContainer%2;
            }else{
                return;
            }

            $($imagesContainer[(currentContainer + 1)%2]).css('z-index',0);
            $($imagesContainer[currentContainer])
                .html(imagesObj[currentImage])
                .css('z-index',99).fadeIn(1000,function(){
                    $($imagesContainer[(currentContainer + 1)%2]).hide();
                    currentImage++;
                    currentContainer++;
                    setTimeout(_toggleImage, 5000);
                });

        }
    }
});

})(jQuery);


(function($) {

$.fn.extend({

    newsRotator: function(options) {
            
        var currentNew = 0;

        var defaults = {
            news: [],
            time: 5000
        };

        options = $.extend(defaults, options);

        var self = this;

               
        _init();

        /***********/
        /* PRIVATE */
        /***********/
        
        function _init(){            
            _toggleNew();
        }

        function  _toggleNew(){
            
            currentNew = currentNew%options.news.length;

            $(self).html(options.news[currentNew].title + '<a href="'+ options.news[currentNew].link + '"> ...read more</a>');
            currentNew++;
            setTimeout(_toggleNew, options.time);
        }
    }
});

})(jQuery);

(function($) {

    $.fn.extend({

        alphaLoader: function() {

            var defaults = {};

            var options = $.extend(defaults, options);

            var $this = this;

            _init();

            /***********/
            /* PRIVATE */
            /***********/

            function _init(){

                if ($.browser.msie && parseInt($.browser.version) < 7) {



                    //fix images with png-source
                    $this.each(function() {

						

                        $(this).attr('class','alphaLoaded');

                        $(this).attr('width',$(this).width());
                        $(this).attr('height',$(this).height());

                        var prevStyle = '';
                        var strNewHTML = '';
                        var imgId = ($(this).attr('id')) ? 'id="' + $(this).attr('id') + '" ' : '';
                        var imgClass = ($(this).attr('class')) ? 'class="' + $(this).attr('class') + '" ' : '';


                        var imgTitle = ($(this).attr('title')) ? 'title="' + $(this).attr('title') + '" ' : '';
                        var imgAlt = ($(this).attr('alt')) ? 'alt="' + $(this).attr('alt') + '" ' : '';
                        var imgAlign = ($(this).attr('align')) ? 'float:' + $(this).attr('align') + ';' : '';
                        var imgHand = ($(this).parent().attr('href')) ? 'cursor:hand;' : '';

						
						prevStyle+= $(this).css('marginRight') != '0px' ? ' margin-right: ' + $(this).css('marginRight') + ';':'';
						prevStyle+= $(this).css('marginLeft') != '0px' ? ' margin-left: ' + $(this).css('marginLeft') + ';':'';
						prevStyle+= $(this).css('marginBottom') != '0px' ? ' margin-bottom: ' + $(this).css('marginBottom') + ';':'';
						prevStyle+= $(this).css('marginTop') != '0px' ? ' margin-top: ' + $(this).css('marginTop') + ';':'';

						prevStyle+= $(this).css('paddingRight') != '0px' ? ' padding-right: ' + $(this).css('paddingRight') + ';':'';
						prevStyle+= $(this).css('paddingLeft') != '0px' ? ' padding-left: ' + $(this).css('paddingLeft') + ';':'';
						prevStyle+= $(this).css('paddingBottom') != '0px' ? ' padding-bottom: ' + $(this).css('paddingBottom') + ';':'';
						prevStyle+= $(this).css('paddingTop') != '0px' ? ' padding-top: ' + $(this).css('paddingTop') + ';':'';

						prevStyle+= $(this).css('borderRight') ? ' border-right: ' + $(this).css('borderRight') + ';':'';
						prevStyle+= $(this).css('borderLeft') ? ' border-left: ' + $(this).css('borderLeft') + ';':'';
						prevStyle+= $(this).css('borderBottom') ? ' border-bottom: ' + $(this).css('borderBottom') + ';':'';
						prevStyle+= $(this).css('borderTop') ? ' border-top: ' + $(this).css('borderTop') + ';':'';

                        var imgStyle = (this.style.cssText);

                        strNewHTML += '<span '+imgId+imgClass+imgTitle+imgAlt;
                        strNewHTML += 'style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+imgAlign+imgHand;
                        strNewHTML += 'width:' + $(this).width() + 'px;' + 'height:' + $(this).height() + 'px;';
                        strNewHTML += 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader' + '(src=\'' + $(this).attr('src') + '\', sizingMethod=\'scale\');';
                        strNewHTML += imgStyle+'"></span>';

						if (prevStyle != ''){
                            strNewHTML = '<span style="position:relative;display:inline-block;'+prevStyle+imgHand+'width:' + $(this).width() + 'px;' + 'height:' + $(this).height() + 'px;'+'">' + strNewHTML + '</span>';
                        }

                        $(this).css({
                            visibility:'hidden',
                            position:'absolute'
                        });

                        $(this).after(strNewHTML);

                    });

                }
            }
        }
    });

})(jQuery);

$(document).ready(function(){

	$('img').not('#image_rotator img').not('#people_videos .thumb').alphaLoader();

	
});