﻿/* ------------------------------------------------------------------------
	s3Slider
	
	Developped By: Boban KariЕЎik -> http://www.serie3.info/
        CSS Help: MГ©szГЎros RГіbert -> http://www.perspectived.com/
	Version: 1.0
	
	Copyright: Feel free to redistribute the script/modify it, as
			   long as you leave my infos at the top.
------------------------------------------------------------------------- */


(function($){  

    $.fn.s3Slider = function(vars) {       
        
        var element     = this;
        var timeOut     = (vars.timeOut != undefined) ? vars.timeOut : 4000;
        var current     = null;
        var timeOutFn   = null;
        var faderStat   = true;
        var mOver       = false;
        var items       = $("#" + element[0].id + "Content ." + element[0].id + "Image");
        var itemsSpan   = $("#" + element[0].id + "Content ." + element[0].id + "Image span");
            
        items.each(function(i) {
    
            $(items[i]).mouseover(function() {
               mOver = true;
            });
            
            $(items[i]).mouseout(function() {
                mOver   = false;
                fadeElement(true);
            });
            
        });
        
        var fadeElement = function(isMouseOut) {
            var thisTimeOut = (isMouseOut) ? (timeOut/2) : timeOut;
            thisTimeOut = (faderStat) ? 10 : thisTimeOut;
            if(items.length > 0) {
                timeOutFn = setTimeout(makeSlider, thisTimeOut);
            } else {
                console.log("Poof..");
            }
        }
        
        var makeSlider = function() {
            current = (current != null) ? current : items[(items.length-1)];
            var currNo      = jQuery.inArray(current, items) + 1
            currNo = (currNo == items.length) ? 0 : (currNo - 1);
            var newMargin   = $(element).width() * currNo;
            if(faderStat == true) {
                if(!mOver) {
                    $(items[currNo]).fadeIn((timeOut/6), function() {
                        if($(itemsSpan[currNo]).css('bottom') == 0) {
                            $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                                faderStat = false;
                                current = items[currNo];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        } else {
                            $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                                faderStat = false;
                                current = items[currNo];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        }
                    });
                }
            } else {
                if(!mOver) {
                    if($(itemsSpan[currNo]).css('bottom') == 0) {
                        $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                            $(items[currNo]).fadeOut((timeOut/6), function() {
                                faderStat = true;
                                current = items[(currNo+1)];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        });
                    } else {
                        $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                        $(items[currNo]).fadeOut((timeOut/6), function() {
                                faderStat = true;
                                current = items[(currNo+1)];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        });
                    }
                }
            }
        }
        
        makeSlider();

    };  

})(jQuery);

/* =========================================================

// jquery.innerfade.js

// Datum: 2008-02-14
// Firma: Medienfreunde Hofmann & Baldes GbR
// Author: Torsten Baldes
// Mail: t.baldes@medienfreunde.com
// Web: http://medienfreunde.com

// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/
// and Ralf S. Engelschall http://trainofthoughts.org/

 *
 *  <ul id="news">
 *      <li>content 1</li>
 *      <li>content 2</li>
 *      <li>content 3</li>
 *  </ul>
 *
 *  $('#news').innerfade({
 *	  animationtype: Type of animation 'fade' or 'slide' (Default: 'fade'),
 *	  speed: Fading-/Sliding-Speed in milliseconds or keywords (slow, normal or fast) (Default: 'normal'),
 *	  timeout: Time between the fades in milliseconds (Default: '2000'),
 *	  type: Type of slideshow: 'sequence', 'random' or 'random_start' (Default: 'sequence'),
 * 		containerheight: Height of the containing element in any css-height-value (Default: 'auto'),
 *	  runningclass: CSS-Class which the container getвЂ™s applied (Default: 'innerfade'),
 *	  children: optional children selector (Default: null)
 *  });
 *

// ========================================================= */


jQuery(document).ready(function() {
    jQuery('.entry img').each(function() {
        var maxWidth = 650; // Max width for the image
        var maxHeight = 1000;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
        var width = $(this).width();    // Current image width
        var height = $(this).height();  // Current image height

        // Check if the current width is larger than the max
        if(width > maxWidth){
            ratio = maxWidth / width;   // get ratio for scaling image
            jQuery(this).css("width", maxWidth); // Set new width
            jQuery(this).css("height", height * ratio);  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        }

        // Check if current height is larger than max
        if(height > maxHeight){
            ratio = maxHeight / height; // get ratio for scaling image
            jQuery(this).css("height", maxHeight);   // Set new height
            jQuery(this).css("width", width * ratio);    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
        }
    });
    jQuery('.toggle-top-views').click(function(){
		if(jQuery(this).attr('title') == 'Топ за все время'){
			jQuery(this).attr('title', 'Топ за месяц');
		}else{
			jQuery(this).attr('title', 'Топ за все время');
		}
		
        jQuery('.recentposts ul').toggleClass('hide');
        jQuery('.recentposts h3 .top-views-title').toggleClass('hide');
        
    });

    jQuery('.comment-body img').each(function() {
//        var maxWidth = 620; // Max width for the image
        var maxWidth = jQuery(this).parent().width()-6; // Max width for the image
        var maxHeight = 600;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
        var width = $(this).width();    // Current image width
        var height = $(this).height();  // Current image height

        // Check if the current width is larger than the max
        if(width > maxWidth){
            ratio = maxWidth / width;   // get ratio for scaling image
            jQuery(this).css("width", maxWidth); // Set new width
            jQuery(this).css("height", height * ratio);  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        }

        // Check if current height is larger than max
        if(height > maxHeight){
            ratio = maxHeight / height; // get ratio for scaling image
            jQuery(this).css("height", maxHeight);   // Set new height
            jQuery(this).css("width", width * ratio);    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
        }
    });
    
});

function overPunkt(obj_listPunkt)
{
obj_listPunkt.childNodes[1].style.display="block";
obj_listPunkt.childNodes[1].style.top=obj_listPunkt.offsetHeight;
obj_listPunkt.style.background="url('http://funnygifts.ru/wp-content/themes/smile/images/dropmenuhover.gif    ')";
obj_listPunkt.style.padding=0;
color_text=obj_listPunkt.style.color;
obj_listPunkt.style.color="#ffffff";
obj_listPunkt.className = "punkt punkt_a";
}

function overPunkta(obj_listPunkta)
{
obj_listPunkt.style.color="#ffffff";
}

function outPunkt(obj_listPunkt)
{
obj_listPunkt.childNodes[1].style.display="none";
obj_listPunkt.style.background="url('') no-repeat 91px 20px";
obj_listPunkt.style.padding=0;
obj_listPunkt.style.paddingBottom=0;
obj_listPunkt.childNodes[0].style.border="none";
obj_listPunkt.style.color=color_text;
obj_listPunkt.className = "punkt";
}
