
/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){$.fn.superfish=function(op){var sf=$.fn.superfish,c=sf.c,$arrow=$(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),over=function(){var $$=$(this),menu=getMenu($$);clearTimeout(menu.sfTimer);$$.showSuperfishUl().siblings().hideSuperfishUl();},out=function(){var $$=$(this),menu=getMenu($$),o=sf.op;clearTimeout(menu.sfTimer);menu.sfTimer=setTimeout(function(){o.retainPath=($.inArray($$[0],o.$path)>-1);$$.hideSuperfishUl();if(o.$path.length&&$$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}},o.delay);},getMenu=function($menu){var menu=$menu.parents(['ul.',c.menuClass,':first'].join(''))[0];sf.op=sf.o[menu.serial];return menu;},addArrow=function($a){$a.addClass(c.anchorClass).append($arrow.clone());};return this.each(function(){var s=this.serial=sf.o.length;var o=$.extend({},sf.defaults,op);o.$path=$('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){$(this).addClass([o.hoverClass,c.bcClass].join(' ')).filter('li:has(ul)').removeClass(o.pathClass);});sf.o[s]=sf.op=o;$('li:has(ul)',this)[($.fn.hoverIntent&&!o.disableHI)?'hoverIntent':'hover'](over,out).each(function(){if(o.autoArrows)addArrow($('>a:first-child',this));}).not('.'+c.bcClass).hideSuperfishUl();var $a=$('a',this);$a.each(function(i){var $li=$a.eq(i).parents('li');$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});});o.onInit.call(this);}).each(function(){var menuClasses=[c.menuClass];if(sf.op.dropShadows&&!($.browser.msie&&$.browser.version<7))menuClasses.push(c.shadowClass);$(this).addClass(menuClasses.join(' '));});};var sf=$.fn.superfish;sf.o=[];sf.op={};sf.IE7fix=function(){var o=sf.op;if($.browser.msie&&$.browser.version>6&&o.dropShadows&&o.animation.opacity!=undefined)
this.toggleClass(sf.c.shadowClass+'-off');};sf.c={bcClass:'sf-breadcrumb',menuClass:'sf-js-enabled',anchorClass:'sf-with-ul',arrowClass:'sf-sub-indicator',shadowClass:'sf-shadow'};sf.defaults={hoverClass:'sfHover',pathClass:'overideThisToUse',pathLevels:1,delay:800,animation:{opacity:'show'},speed:'normal',autoArrows:true,dropShadows:true,disableHI:false,onInit:function(){},onBeforeShow:function(){},onShow:function(){},onHide:function(){}};$.fn.extend({hideSuperfishUl:function(){var o=sf.op,not=(o.retainPath===true)?o.$path:'';o.retainPath=false;var $ul=$(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass).find('>ul').hide().css('visibility','hidden');o.onHide.call($ul);return this;},showSuperfishUl:function(){var o=sf.op,sh=sf.c.shadowClass+'-off',$ul=this.addClass(o.hoverClass).find('>ul:hidden').css('visibility','visible');sf.IE7fix.call($ul);o.onBeforeShow.call($ul);$ul.animate(o.animation,o.speed,function(){sf.IE7fix.call($ul);o.onShow.call($ul);});return this;}});})(jQuery);
/*
 * Supersubs v0.2b - jQuery plugin
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 *
 * This plugin automatically adjusts submenu widths of suckerfish-style menus to that of
 * their longest list item children. If you use this, please expect bugs and report them
 * to the jQuery Google Group with the word 'Superfish' in the subject line.
 *
 */
;(function($){$.fn.supersubs=function(options){var opts=$.extend({},$.fn.supersubs.defaults,options);return this.each(function(){var $$=$(this);var o=$.meta?$.extend({},opts,$$.data()):opts;var fontsize=$('<li id="menu-fontsize">&#8212;</li>').css({'padding':0,'position':'absolute','top':'-999em','width':'auto'}).appendTo($$).width();$('#menu-fontsize').remove();$ULs=$$.find('ul');$ULs.each(function(i){var $ul=$ULs.eq(i);var $LIs=$ul.children();var $As=$LIs.children('a');var liFloat=$LIs.css('white-space','nowrap').css('float');var emWidth=$ul.add($LIs).add($As).css({'float':'none','width':'auto'}).end().end()[0].clientWidth/fontsize;emWidth+=o.extraWidth;if(emWidth>o.maxWidth){emWidth=o.maxWidth;}
else if(emWidth<o.minWidth){emWidth=o.minWidth;}
emWidth+='em';$ul.css('width',emWidth);$LIs.css({'float':liFloat,'width':'100%','white-space':'normal'}).each(function(){var $childUl=$('>ul',this);var offsetDirection=$childUl.css('left')!==undefined?'left':'right';$childUl.css(offsetDirection,emWidth);});});});};$.fn.supersubs.defaults={minWidth:9,maxWidth:25,extraWidth:0};})(jQuery);


/********************************************************************************************
************************** CUSTOM ***********************************************************
********************************************************************************************/



$(document).ready(function($) {
	// Top pages
	$('#top_page ul.top_menu').supersubs({ 
            minWidth:    10,   // minimum width of sub-menus in em units 
            maxWidth:    30,   // maximum width of sub-menus in em units 
            extraWidth:  1    // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish({
			delay: 200,
            animation:   {'marginLeft':'0px',opacity:'show',height:'show'},  // fade-in and slide-down animation
            speed: 'fast',
            onBeforeShow: function(){ this.css('marginLeft','-10px'); },
            dropShadows: false,
            autoArrows: false
            
	}); 

/***********************************************************************************************************/  
	
	// Bottom menu Menu
	$('#bottom_menu ul').supersubs({ 
            minWidth:    7,   // minimum width of sub-menus in em units 
            maxWidth:    30,   // maximum width of sub-menus in em units 
            extraWidth:  1    // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish({
			delay: 200,
            animation:   {'marginLeft':'0px',opacity:'show',height:'show'},  // fade-in and slide-down animation
            speed: 'fast',
            onBeforeShow: function(){ this.css('marginLeft','-10px'); },
            dropShadows: false,
            autoArrows: false
            
	});
    
/***********************************************************************************************************/      
    
    // Footer link hover delay

       
       $('.widget_categories ul li a,.widget_links ul li a,.tab_cate li a,.widget_pages ul li a').hover(function() {
    	$(this).animate({paddingLeft: '16px'}, 200);
    	}, function() {
    	$(this).animate({paddingLeft: '12px'}, 200);
    });
    
 
/***********************************************************************************************************/        
       
    // Post Caption
	$('.item').hover(function(){  
		$('.post_text', this).stop().animate({top:'11px'},{queue:false,duration:300});  
		}, function() {  
		$('.post_text', this).stop().animate({top:'130px'},{queue:false,duration:300});  
		}); 
        


/***********************************************************************************************************/          
    
    // Featured Post scrollable    
    $(".scrollable").scrollable({
        speed: '400'
    });
        
    //Featured Posts tabs
    $("ul.posttabs").tabs(".post_panes_element",{
        effect: 'default',
        history: true
    });
    
    // popular_related_post
    $("ul.popular_related_tabs").tabs(".popular_related_element",{});
    
    $("ul.content_tab_title").tabs(".tab_element");

     
        
/***********************************************************************************************************/  

    $(".entry a img,#slider2 div a img,.positionelement a img").css({
				opacity: 1
			});
		$(".entry a img,#slider2 div a img,.positionelement a img").hover(function() {
			$(this).stop().animate({
				opacity: 0.8
				}, 300);
			},function() {
			$(this).stop().animate({
				opacity: 1
				}, 500);
		});
        
        // lightbox and hyperlink hover
        $(".post_thumb .images_lightbox,.po_re_container .images_lightbox,.post_thumb .images_hyperlink,.positionelement .images_hyperlink,.positionelement .images_lightbox,.po_re_container .images_hyperlink,.small_lightbox,.small_hyperlink").css({
				opacity: 0,
                display: 'block'
			});
		$(".post_thumb .images_lightbox,.po_re_container .images_lightbox,.post_thumb .images_hyperlink,.positionelement .images_hyperlink,.positionelement .images_lightbox,.po_re_container .images_hyperlink,.small_lightbox,.small_hyperlink").hover(function() {
			$(this).stop().animate({
				opacity: 0.6
				}, 300);
			},function() {
			$(this).stop().animate({
				opacity: 0
				}, 500); 
		});

/***********************************************************************************************************/ 

(function($)
{
	$.fn.image_preloader = function(options) 
	{
		var defaults = 
		{
			repeatedCheck: 500,
			fadeInSpeed: 1000,
			delay:600,
			callback: ''
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function()
		{
			var imageContainer = jQuery(this),
				images = imageContainer.find('img').css({opacity:0, visibility:'hidden'}),
				imagesToLoad = images.length;				
				
				imageContainer.operations =
				{	
					preload: function()
					{	
						var stopPreloading = true;
						
						images.each(function(i, event)
						{	
							var image = $(this);
							
							
							if(event.complete == true)
							{	
								imageContainer.operations.showImage(image);
							}
							else
							{
								image.bind('error load',{currentImage: image}, imageContainer.operations.showImage);
							}
							
						});
						
						return this;
					},
					
					showImage: function(image)
					{	
						imagesToLoad --;
						if(image.data.currentImage != undefined) { image = image.data.currentImage;}
												
						if (options.delay <= 0) image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
												 
						if(imagesToLoad == 0)
						{
							if(options.delay > 0)
							{
								images.each(function(i, event)
								{	
									var image = $(this);
									setTimeout(function()
									{	
										image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
									},
									options.delay*(i+1));
								});
								
								if(options.callback != '')
								{
									setTimeout(options.callback, options.delay*images.length);
								}
							}
							else if(options.callback != '')
							{
								(options.callback)();
							}
							
						}
						
					}

				};
				
				imageContainer.operations.preload();
		});
		
	}
})($);

/***********************************************************************************************************/


/***********************************************************************************************************/ 
/////////////////////////////// MENU RIGHT

$('.top_right_menu').each(function () {
    $("a.click_tab").click(function(){ return false; });
    
    var time= 200;
    
    var trigger1 = $('a.a_user_tooltip', this);
    var trigger2 = $('a.a_menu_rss', this);
    var trigger3 = $('.a_menu_search', this);
    var info1 = $('#box_user', this).css('opacity', 0);
    var info2 = $('#box_rss',this).css('opacity', 0);
    var info3 = $('#box_search',this).css('opacity', 0);
    
    var delayTime=200;
    var hideDelayTimer=300;
    var isTab=0;
   // var 
    
    var showing=false;
    
    function _show(obj){
            obj.css({ display: 'block'})
            .animate({top: '29px',opacity: 1,filter: '' }, time, 'swing');
    }
    
    function _hide(obj){
         showing=false;
            obj.animate({ top: '39px',opacity: 0,filter: ''}, time, 'swing', function () {
                obj.css('display', 'none');
            });
    }

    $([trigger1.get(0), info1.get(0)]).mouseover(function () {
          if(hideDelayTimer){
                clearTimeout(hideDelayTimer);
            }
            isTab=1;
            
          //  $('#logo').html(isTab);
            _hide(info2);
            _hide(info3);
            if(hideDelayTimer){
                clearTimeout(hideDelayTimer);
            }
            
            showing=true;
            
            info1.css({ display: 'block'
            }).animate({top: '29px',opacity: 1,filter: '' 
            }, time, 'swing',function(){
                showing=false;
            });
       
        return false;
    }).mouseout(function () {
       
          //  if(showing && isTab==1) { return ;}
            
            if(hideDelayTimer){
                clearTimeout(hideDelayTimer);
            }
            
            hideDelayTimer=setTimeout(function(){
                hideDelayTimer = null;
                isTab=0;
               // showing=false;
                info1.animate({ top: '39px',opacity: 0,filter: ''
                }, time, 'swing', function () {
                    showing = false;
                    info1.css('display', 'none');
                });
                
                
            },delayTime);
            
        return false;
    }); // end box hover 1
    
    $([trigger2.get(0), info2.get(0)]).mouseover(function () {
            isTab=2;
           // $('#logo').html(isTab);
            _hide(info1);
             _hide(info3);
            if(hideDelayTimer){
                clearTimeout(hideDelayTimer);
            }
           showing=true;
             
            info2.css({ display: 'block'
            }).animate({top: '29px',opacity: 1,filter: '' 
            }, time, 'swing', function() {
                showing=false;
            });
       
        return false;
    }).mouseout(function () {
        
        
        // if(showing && isTab==2) { return ;}
         
         if(hideDelayTimer){
                clearTimeout(hideDelayTimer);
            }
         
            hideDelayTimer=setTimeout(function(){
                hideDelayTimer = null;
                isTab=0;
              //  showing=true;
            info2.animate({ top: '39px',opacity: 0,filter: ''
            }, time, 'swing', function () {
                //shown = false;
                showing=false;
                info2.css('display', 'none');
            });

        },delayTime);
        
        return false;
    }); // end box hover 2
    
    $([trigger3.get(0), info3.get(0)]).mouseover(function () {
        
           isTab=3;
           // $('#logo').html(isTab);
            _hide(info1);
            _hide(info2);
            if(hideDelayTimer){
                clearTimeout(hideDelayTimer);
            }
             showing=true;
             
            info3.css({ display: 'block'
            }).animate({top: '29px',opacity: 1,filter: '' 
            }, time, 'swing', function() {
                showing=false;
            });
       
        return false;
    }).mouseout(function (){
       
        
        //   if(showing && isTab==3) { return ;}
            
            if(hideDelayTimer){
                clearTimeout(hideDelayTimer);
            }
         
            hideDelayTimer=setTimeout(function(){
                hideDelayTimer = null;
                isTab=0;
               // showing=true;
                info3.animate({ top: '39px',  opacity: 0,filter: ''
            }, time, 'swing', function (){
                //shown = false;
                showing=false;
                info3.css('display', 'none');
            });

        },delayTime);
        
        return false;
    }); // end box hover 3
            
});

/*********************************************AJAX LOGIN******************************************************/ 



    $('#box_login .loginFrom').submit(function(){
       // alert('ok'); return false;
            var msg='';
            var form=$(this);
            var log=$('.loginFrom input[name=log]').val();
            var pwd=$('.loginFrom input[name=pwd]').val();
            var redir=$('.loginFrom input[name=redirect_to]').val();
            
            var rememberme=$('.loginFrom input[name=rememberme]').val();
            var filter = /^([a-zA-Z0-9_.-])+$/;
            
            
           // alert(log+'===='+pwd);
            if(log=='' || !filter.test(log)){
              //  alert('Please enter username !');
              $('.loginFrom input[name=log]').css({'border': '1px solid red'});
                return false;
            }
            
            
            
             if(pwd==''){
                // alert(' Please enter password !');
                $('.loginFrom input[name=pwd]').css({'border': '1px solid red'});
                return false;
            }
            var mdate=new Date();
         $.ajax({
               type: "POST",
               url: ajax_theme_url+'?rand='+(mdate.getTime()),
               data: {action : 'wts_theme_ajax_login',log: log, pwd : pwd , rememberme : rememberme,redirect_to : redir},
               dataType: "html",
               success: function(html){
               var state =html.split("\n",2);
                if(state[0]==1) /// sucesss
                 {
                    //form.parent('#box_login').append(state[1]);
                   // form.hide();
                   window.location=current_page;
                 }
                else
                 {
                   // alert(state[1]);
                    // alert(' Username or Pass word wrong ! ');
                    $('.loginFrom input[name=log]').css({'border': '1px solid red'});
                    $('.loginFrom input[name=pwd]').css({'border': '1px solid red'});
                 }
               }
             }); 
             return  false;
        });
        
        
        $('#box_user #box_register form.register').submit(function(){
            $('#box_register #box_register_loading').removeClass('hide').addClass('show');
            $('#box_register .content').removeClass('show').addClass('hide');
          //  alert('ok'); return false;
            var form =$(this);
            var user=$('form.register input[name=user_login]').val();
            var email=$('form.register input[name=user_email]').val();
            var filteruser = /^([a-zA-Z0-9_.-])+$/;
            var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
             var check=true;
            if(user=='' || !filteruser.test(user)){

             //  alert('Please enter username !');
                $('form.register input[name=user_login]').css({'border':  '1px solid red'});
                $('#box_register #box_register_loading').removeClass('show').addClass('hide');
                        $('#box_register .content').removeClass('hide').addClass('show');
                check=false;
            }
            if (!filter.test(email)) {
                // alert('Please provide a valid email address');
                 $('form.register input[name=user_email]').css({'border':  '1px solid red'});
                 $('#box_register #box_register_loading').removeClass('show').addClass('hide');
                        $('#box_register .content').removeClass('hide').addClass('show');
                check=false;
            }
            
            
            if(check==false){
                return false;
            }
            
        //    alert(user);
            var mdate=new Date();
           // alert(mdate.getTime());
         $.ajax({
               type: "POST",
               url: ajax_theme_url+'?rand='+(mdate.getTime()),
               data: {action : 'wts_theme_ajax_register',user_login: user, user_email : email },
               dataType: "html",
               success: function(html){
              //  alert(html);
                var state='';
                 state = html.split("\n",2);
                    if(state[0]==1){
                        form.hide();
                        $('#box_register #box_register_loading').removeClass('show').addClass('hide');
                        $('#box_register .content').removeClass('hide').addClass('show');
                        form.parents('#box_user #box_register').html('Registration complete. Please check your e-mail to get password !');
                       // $('#box_user').hide(1000);
                    }else{
                        form.hide();
                        
                        $('#box_register #box_register_loading').removeClass('show').addClass('hide');
                        $('#box_register .content').removeClass('hide').addClass('show');
                        
                        $('#box_register .content .error').html(state[1]).fadeIn(400);
                        $('form.register input[name=user_login]').val('');
                        $('form.register input[name=user_email]').val('');
                        $('#box_register #do_again').removeClass('hide').addClass('show');
                        
                        // callback function 
                        $('#box_register #do_again').click(function(){
                            $(this).removeClass('show').addClass('hide');
                            $('#box_register .error').hide();
                            $('#box_register form.register').show();
                        });
                    }
               }

             }); 
             return  false;
        });

/*************************************************************************************/

}); // end document ready .

function removeloader()
{
	$('#body .loader').removeClass('loader');
}


    

    
