jQuery(document).ready(function(){

	/*Initialize pretty galery
	 for more settings see http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/documentation/
	 */
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		autoplay_slideshow: false,
		theme: 'light_rounded'
	  
	});
	
	/*initialize tabs*/
	jQuery(function() {
		jQuery('.cosmo-tabs').tabs({ fxFade: true, fxSpeed: 'fast' });
	});

	/*toogle*/
	/*Case when by default the toggle is closed */
	jQuery(".open_title").toggle(function(){ 
			jQuery(this).next('div').slideDown();
			jQuery(this).find('a').removeClass('show');
			jQuery(this).find('a').addClass('hide');
			jQuery(this).find('.title_closed').hide();
			jQuery(this).find('.title_open').show();
		}, function () {
		
			jQuery(this).next('div').slideUp();
			jQuery(this).find('a').removeClass('hide');
			jQuery(this).find('a').addClass('show');		 
			jQuery(this).find('.title_open').hide();
			jQuery(this).find('.title_closed').show();
			
	});

	/*Case when by default the toggle is oppened */		
	jQuery(".close_title").toggle(function(){ 
			jQuery(this).next('div').slideUp();
			jQuery(this).find('a').removeClass('hide');
			jQuery(this).find('a').addClass('show');		 
			jQuery(this).find('.title_open').hide();
			jQuery(this).find('.title_closed').show();
		}, function () {
			jQuery(this).next('div').slideDown();
			jQuery(this).find('a').removeClass('show');
			jQuery(this).find('a').addClass('hide');
			jQuery(this).find('.title_closed').hide();
			jQuery(this).find('.title_open').show();
			
	});	
	
	/*Accordion*/
	jQuery('.cosmo-acc-container').hide();
	jQuery('.cosmo-acc-trigger:first').addClass('active').next().show();
	jQuery('.cosmo-acc-trigger').click(function(){
		if( jQuery(this).next().is(':hidden') ) {
			jQuery('.cosmo-acc-trigger').removeClass('active').next().slideUp();
			jQuery(this).toggleClass('active').next().slideDown();
		}
		return false;
	});
	
	//Slider
	jQuery('#slides').slides({
        "generateNextPrev":SL_BUTTONS ,
        "generatePagination":SL_PAGINATION ,
        "slideSpeed":SL_SLIDESPEED ,
        "effect":SL_EFFECT,
        "randomize":SL_RANDOMIZE,
        "hoverPause":SL_PAUSE,
        "play":SL_PLAYSPEED,

		"preload":true,
		"preloadImage":'/wp-content/themes/blogitty/images/loading.gif',

		"pause":2500,
		"animationStart":function(){
			jQuery('.caption').animate({
				"bottom":-35
			},100);
		},
		"animationComplete": function(current){
			jQuery('.caption').animate({
				"bottom":0
			},200);
			if (window.console && console.log) {
				console.log(current);
			};
		}
	});

	//Scroll to top
	jQuery(window).scroll(function() {
		if(jQuery(this).scrollTop() != 0) {
			jQuery('#toTop').fadeIn();	
		} else {
			jQuery('#toTop').fadeOut();
		}
	});
	jQuery('#toTop').click(function() {
		jQuery('body,html').animate({scrollTop:0},300);
	});

    
	//Superfish menu
	jQuery("ul.sf-menu").supersubs({
				minWidth:    12,
				maxWidth:    27,
				extraWidth:  1
			}).superfish({
				delay: 200,
				speed: 'fast'
			});
	
	jQuery('.demo_btn').toggle(function() {
		jQuery(this).parent().find('div.demo_code').show();
		jQuery(this).html('- Code Snippet');
	  
	}, function() {
		jQuery(this).parent().find('div.demo_code').hide();
		jQuery(this).html('+ Code Snippet');
	  
	});


    /* front-page  */
    jQuery(".cosmo-swap").hoverIntent(makeTall,makeShort);

    function makeTall(){  jQuery(this).animate({"height":240},350);}
    function makeShort(){ jQuery(this).animate({"height":166},350);}

    jQuery('.cosmo-twit-container').vTicker({
        speed: 500,
        pause: 6000,
        animation: 'fade',
        mousePause: true,
        showItems: 3
    });
	
	jQuery('.fade').mosaic({speed : 350});
	
	jQuery('.flickr_badge_image').each(function(index){
		var x = index % 3;
		if(index !=1 && x == 2){
			
			jQuery(this).addClass('last');
		} 
	});
});

	function setBgColor(rb_id){
		jQuery('#' + rb_id).trigger('click');
		changeBgColor(rb_id);
	}
	
	function setBgImage(rb_id){
		jQuery('#' + rb_id).trigger('click');
		changeBgImage(rb_id);
	}
	
    function send_contact_mail( action , form , container ){
        jQuery( document ).ready(function(){

            var tomail  = jQuery( form ).find("input[name=\"tomail\"]").val();
            var name  = jQuery( form ).find("input[name=\"name\"]").val();
            var email = jQuery( form ).find("input[name=\"email\"]").val();
            var mssg  = jQuery( form ).find("textarea[name=\"message\"]").val();
            jQuery.post( AJAXURL ,
                    {
                        "action" : action ,
                        "tomail" : tomail,
                        "name" : name,
                        "email" : email,
                        "message" : mssg,
                        "btn_send" : "btn_send"
                    } ,
                    function( data ){
                        jQuery( container ).html( data );
						if(jQuery.trim(data) == 'Email sent successfully'){
							jQuery('#name').val('');
							jQuery('#email').val('');
							jQuery('#comment').val('');
							jQuery( container ).css('color','green');
						}
						else{
							jQuery( container ).css('color','red');
						}
            });
        });
    }

