$(document).ready(function(){
// Close on hover
        $(".contentBox, .flatBox").hover(function(){
            $(this).find('.close').stop(true, true).fadeIn(250);
        },function(){
            $(this).find('.close').stop(true, true).fadeOut(350);
        });
        $(".contentBox .close, .flatBox .close").click(function(){
            $(this).parent().slideUp(750);
        });
// Expose
        $(".media").hover(function(){
            $(this).find('.expose').stop(true, true).fadeIn(250);
        },function(){
            $(this).find('.expose').stop(true, true).fadeOut(350);
        });
        $(".media .expose").click(function(){
            $(this).parent().expose();
        });
// Add mag glass for pretty photo enabled elements
        $("a[rel='prettyPhoto']").hover(function(){
            $(this).find('img, iframe').stop(true, true).fadeTo(250, 0.5);
            $(this).parent().addClass("mag");
        },function(){
            $(this).find('img, iframe').stop(true, true).fadeTo(350, 1);
            $(this).parent().removeClass("mag");
        });
// Warning box
        $(".warning").hover(function(){
            $(this).addClass("borderWarning");

        },function(){
            $(this).removeClass("borderWarning");
        });
// Calendar
        $(":date").dateinput({
	        format: 'dddd, dd mmmm yyyy',
	        speed: 'fast',
	        firstDay: 1
        });
// Form validator
        $(".inputForm").validator({
	        formEvent: 'submit',
	        errorClass: 'error',
	        inputEvent: 'keyup',
	        speed: 'slow',
	        message: ''
         });
        $.tools.validator.fn("[data-equals]", "Value not equal with the $1 field", function(input) {
	     var name = input.attr("data-equals"),
		  field = this.getInputs().filter("[name=" + name + "]");
	     return input.val() == field.val() ? true : [name];
        });
// Pretty Photo
        $("a[rel^='prettyPhoto']").prettyPhoto({
			animation_speed: 'fast', 
			slideshow: 5000,
			autoplay_slideshow: false,
			opacity: 0.80,
			show_title: true,
			allow_resize: true,
			default_width: 500,
			default_height: 344,
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'pp_default', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
			horizontal_padding: 20,
			hideflash: false,
			wmode: 'opaque',
			autoplay: true,
			modal: false,
			deeplinking: true,
			overlay_gallery: true,
			keyboard_shortcuts: false
        });
// Nice hover
      $(".boxBlue, .boxRed, .boxBlack, .boxWhite, .boxGreen, .boxOrange").hover(function(){
            $(this).stop(true, true).fadeTo(250, 0.8);
        },function(){
            $(this).stop(true, true).fadeTo(250, 1.0);
        });
// Table sorter
        $("#sort").tablesorter( {sortList: [[0,0], [1,0]]} );
// Tooltip
        $(".Tooltip").tooltip({effect: 'slide', slideOffset: 10, bounce: true});
// Scrollable
        $.easing.custom = function (x, t, b, c, d) {
	     var s = 1.70158;
	     if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
	     return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
        }
        $("div.scrollable").scrollable({easing: 'custom', speed: 700, circular: true});
// Drop Down
       $(function(){
            $("ul.dropdown li").hover(function(){
               $('ul:first',this).stop(true, true).slideDown(250);
            },function(){
               $('ul:first',this).stop(true, true).slideUp(500);
            });
       $("ul.dropdown li ul li:has(ul)").find("a:first").append(" > ");
       });
// Tabs
        $(function() {
	     $(".css-tabs:first").tabs(".css-panes:first > div");
        });
// Modal Windows
       var triggers = $("#modalWindow").overlay({
	       mask: {
		     color: '#000',
		     loadSpeed: 200,
		     opacity: 0.8,
	     },
	     closeOnClick: false
        });
// Modal Window Auto
       var triggers = $(".modalWindow").overlay({
       top: 200,
	       mask: {
		     color: '#000',
		     loadSpeed: 200,
		     opacity: 0.8,
	     },
	     closeOnClick: false,
                  oneInstance: false,
                load: true
        });

// YouTube Chromeless Video        
        $('a.video-link').ytchromeless();
        
// Handle dead images with specific ID
        $("img#testimg").error(function(){
             $(this).hide();
        })
        .attr("src", "templates/ConSpiraSy/images/blank.gif");
// Fancy banner show up
         $(".banner").fadeIn(1500);
});
/* SIMPLE CAPTCHA BY STOILJKOVIC */
      function randomString() {
	     var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
      	var string_length = 8;
      	var randomstring = '';
     	for (var i=0; i<string_length; i++) {
	     	var rnum = Math.floor(Math.random() * chars.length);
	     	randomstring += chars.substring(rnum,rnum+1);
	   }
	   document.formCaptcha.fieldCaptcha.value = randomstring;
      }
