
jQuery(document).ready(function() {
						   
	if(jQuery('body').is('.scroll-to-top')){
		jQuery('body').append('<a href="#top" id="back-to-top">Back To Top</a>');
		jQuery(function () {
			jQuery(window).scroll(function () {
				if (jQuery(this).scrollTop() > 100) {
					jQuery('#back-to-top').fadeIn();
				} else {
					jQuery('#back-to-top').fadeOut();
				}
			});
			// scroll body to 0px on click
			jQuery('#back-to-top').click(function () {
				var $delay = jQuery(window).scrollTop();
				jQuery('body,html').animate({
					scrollTop: 0
				}, 2000*Math.atan($delay/3000));
				return false;
			});
		});
	}
	/* Start Main Menu */
	jQuery("#dropmenu ul").css({display: "none"}); // Opera Fix
	jQuery("#dropmenu>li").each(function(){
		var $sub = jQuery(this).find('.sub-menu:first');
		if($sub.length == 0)
			$sub = jQuery(this).find('.children:first');
		if($sub.length >0){
			$sub.css({visibility: "hidden",display: "block"});
			var width = $sub.width();
			width = 0 - width/2;
			$sub.css('margin-left',width+'px');
			$sub.css({visibility: "visible",display: "none"});
		}
			
	});

	jQuery("#dropmenu>li:first-child>a").addClass("first");

	jQuery(".menu-main-navigation-container").each(function(){jQuery(this).find('li:first-child').addClass("first");});
	jQuery(".menu-footer-container").each(function(){jQuery(this).find('li:first-child').addClass("first");});
	jQuery(".menu-topbar-container").each(function(){jQuery(this).find('li:first-child').addClass("first");});
	jQuery("#author .contact-icons a").last().css('border','none');
	/*spin*/
	jQuery('.overlay.preload').spin({
		lines: 12, // The number of lines to draw
		length: 7, // The length of each line
		width: 4, // The line thickness
		radius: 10, // The radius of the inner circle
		color: '#000', // #rgb or #rrggbb
		speed: 1, // Rounds per second
		trail: 60, // Afterglow percentage
		shadow: false // Whether to render a shadow
	});
	jQuery('#slideload').spin({
		lines: 12, // The number of lines to draw
		length: 7, // The length of each line
		width: 4, // The line thickness
		radius: 10, // The radius of the inner circle
		color: '#000', // #rgb or #rrggbb
		speed: 1, // Rounds per second
		trail: 60, // Afterglow percentage
		shadow: false // Whether to render a shadow
	});
	jQuery('div.widget-slider-content').each(function(){
		$wrap = jQuery(this);
		$wrap.find('.widget-slider-list').width($wrap.width());
		$panel = $wrap.parent();
		if($wrap.find('.widget-slider-list').length !=0)
			$wrap.cycle({
				prev:   $panel.find('.widget-slider-back'),
				next:   $panel.find('.widget-slider-forward'),
				speed:  $wrap.attr('data-speed'),
				fx:	 $wrap.attr('data-animate'),
				easing:$wrap.attr('data-easing'),
				timeout:  $wrap.attr('data-delay'),
				sync:true,
				manualTrump:false
			});
	});
	jQuery('div.cycle-wrap').each(function(){
		$wrap = jQuery(this);
		$box = $wrap.closest('div.cycle-box');
		var height = 0;
		$wrap.find('.cycle-content').each(function(){
			if(jQuery(this).height() > height)
				height = jQuery(this).height();
		})
		$wrap.height(height);
		if($wrap.find('.cycle-content').length !=0)
			$wrap.cycle({
				next:   $box.find('.cycleforward'),
				prev:   $box.find('.cycleback'),
				fx:	 $box.attr('data-animate'),
				speed:  $box.attr('data-speed'),
				timeout:  $box.attr('data-delay'),
				easing:$box.attr('data-easing'),
				sync:true,
				manualTrump:false
			});
	});
	jQuery('.portfolio-content.carousel-box').each(function(){
		$wrap = jQuery(this);
		$bar  = $wrap.find('.portfolio-control');
		$content = $wrap.find('.carousel-wrap');
		if($content.length != 0)
			$content.cycle({
				next:$bar.find('.cycleforward'),
				prev:$bar.find('.cycleback'),
				fx:	 $wrap.attr('data-animate'),
				speed:$wrap.attr('data-speed'),
				timeout:$wrap.attr('data-delay'),
				easing:$wrap.attr('data-easing'),
				sync:true,
				manualTrump:false
			});

	});
	/* accordion */
	jQuery(".accordion").each(function(){
		jQuery(this).tabs("div.pane", {tabs: '.tab', effect: 'slide',initialIndex:null});
	});

	/* button */
	jQuery(".button").hover(function(){
		var $hoverBg = jQuery(this).attr('data-hoverBg');
		var $hoverColor = jQuery(this).attr('data-hoverColor');
		if($hoverBg!=undefined){
			jQuery(this).css('background-color',$hoverBg);
		}
		if($hoverColor!=undefined){
			jQuery('span',this).css('color',$hoverColor);
		}
	}, function(){
		var $bg = jQuery(this).attr('data-bg');
		var $color = jQuery(this).attr('data-color');
		if($bg!=undefined){
			jQuery(this).css('background-color',$bg);
		}
		if($color!=undefined){
			jQuery('span',this).css('color',$color);
		}
	});

	/* enable image hover effect */
	var enable_image_hover = function(image){
		if(image.is(".image_icon_zoom,.image_icon_play,.image_icon_doc,.image_icon_link")){
			if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) {} else {
					if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 9) {
						jQuery(image).find(".image_overlay").css("visibility", "hidden");
					image.hover(function(){
						jQuery(".image_overlay",this).css("visibility", "visible");
					},function(){
						jQuery(".image_overlay",this).css("visibility", "hidden");
					});
				}else{
					image.hover(
  					function() {  
							jQuery(".image_thumb",this).stop().animate({"opacity": "0.4"}, "slow"); 
							jQuery(".image_overlay",this).stop().animate({"opacity": "0.8"}, "slow");
					},
  					function() {  
							jQuery(".image_thumb",this).stop().animate({"opacity": "1"}, "slow");
							jQuery(".image_overlay",this).stop().animate({"opacity": "0"}, "slow");
					}
				);}
			}
		}
	}
	/*image*/
	jQuery('.image_no_link').click(function(){
		return false;		
	});

	/*prettyphoto*/
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({theme:themeParam,slideshow:5000,autoplay_slideshow:false});
	jQuery("a[rel^='prettySlide']").each(function(){
		jQuery(this).prettyPhoto({theme: 'facebook',slideshow:5000,autoplay_slideshow:true});
	});


	/* toggler */
	/*jQuery('.toggler .accContent').hide();*/
	/*jQuery('.toggler').each(function(){
		if(jQuery(this).next().is('br')){
			jQuery(this).next().remove();
		}
		$open = jQuery(this).attr('data-open');
		if(! $open)
			jQuery(this).find('.accContent').hide();*/
		jQuery(this).find('.togglebar').click(function() {
			if(jQuery(this).hasClass('accToggler')){
				jQuery(this).removeClass('accToggler').addClass('accTogglerOpen');
				jQuery(this).siblings('.accContent').slideDown();
			}else{
				jQuery(this).removeClass('accTogglerOpen').addClass('accToggler');
				jQuery(this).siblings('.accContent').slideUp();
			}
			//jQuery(this).next().slideToggle();
		});

	/*});*/

	/*jQuery('.toggler .accToggler').removeClass('current');
	jQuery('.toggler .accToggler').click(function() {
		this.className = (this.className == 'accToggler')? 'accTogglerOpen' : 'accToggler';
		jQuery(this).next().slideToggle();
	});*/

/*
	jQuery('.accordion p.close').click(function() {
		jQuery(this).parent().slideUp()
		.prev().removeClass('accTogglerOpen').addClass('accToggler');
	});*/


	/*tips&tab*/
	jQuery('span.tips-wrap').each(function(){
		var position = jQuery(this).attr("data-position");
		var effect = jQuery(this).attr("data-effect");
		var delay = jQuery(this).attr("data-delay");
		jQuery(this).find('span.tips').tooltip({position:position,effect: effect,delay:delay});
	});
	jQuery(".tabs_container").each(function(){
		var $history = jQuery(this).attr('data-history');
		if($history!=undefined && $history == 'true'){
			$history = true;
		}else {
			$history = false;
		}
		var $initialIndex = jQuery(this).attr('data-initialIndex');
		if($initialIndex==undefined){
			$initialIndex = 0;
		}
		jQuery("ul.tabs",this).tabs("div.panes > div", {tabs:'a', effect: 'fade', fadeOutSpeed: -400, history: $history, initialIndex: $initialIndex});
	});
	jQuery(".mini_tabs_container").each(function(){
		var $history = jQuery(this).attr('data-history');
		if($history!=undefined && $history == 'true'){
			$history = true;
		}else {
			$history = false;
		}
		var $initialIndex = jQuery(this).attr('data-initialIndex');
		if($initialIndex==undefined){
			$initialIndex = 0;
		}
		jQuery("ul.mini_tabs",this).tabs("div.panes > div", {tabs:'a', effect: 'fade', fadeOutSpeed: -400, history: $history, initialIndex: $initialIndex});
	});
	if(jQuery.tools.tabs.addEffect != undefined){
		jQuery.tools.tabs.addEffect("slide", function(i, done) {
			this.getPanes().slideUp();
			this.getPanes().eq(i).slideDown(function()  {
				done.call();
			});
		});
	}

	jQuery(".icon_email").each(function(){
		if(jQuery(this).attr('href') != undefined){
			jQuery(this).attr('href',jQuery(this).attr('href').replace("*", "@"));
		}
		jQuery(this).html(jQuery(this).html().replace("*", "@"));
	});
	jQuery(".contact_info_wrap .icon_email").each(function(){
		jQuery(this).attr('href',jQuery(this).attr('href').replace("*", "@"));
		jQuery(this).html(jQuery(this).html().replace("*", "@"));
	});
	/*form validator*/
    if(jQuery.tools.validator != undefined){
        jQuery.tools.validator.addEffect("contact_form", function(errors, event) {
        
			jQuery.each(errors, function(index, error) {
                var input = error.input;
				
                input.addClass('invalid');
            });
        }, function(inputs)  {
            inputs.removeClass('invalid');
        });
        /* contact form widget */
        jQuery('.widget_contact_form .contact_form').validator({effect:'contact_form'}).submit(function(e) {
			var form = jQuery(this);
            if (!e.isDefaultPrevented()) {
                jQuery.post(this.action,{
					'theme_contact_form_submit': 1,
                    'to':jQuery('input[name="contact_to"]').val().replace("*", "@"),
                    'name':jQuery('input[name="contact_name"]').val(),
                    'email':jQuery('input[name="contact_email"]').val(),
                    'content':jQuery('textarea[name="contact_content"]').val()
                },function(data){
                    form.fadeOut('fast', function() {
                         jQuery(this).siblings('p').show();
                    }).delay(3000).fadeIn('fast',function(){
						jQuery(this).find('textarea, input[type=text],input[type=email]').val('');
						jQuery(this).siblings('.success').hide();
						jQuery(this).siblings('.errors').hide();
					});
                });
				e.preventDefault();
            }
        });
        /* contact page form */
        jQuery('.contact_form_wrap .contact_form').validator({effect:'contact_form'}).submit(function(e) {
            var form = jQuery(this);
            if (!e.isDefaultPrevented()) {
                var $id = form.find('input[name="contact_widget_id"]').val();
                jQuery.post(this.action,{
					'theme_contact_form_submit': 1,
                    'to':jQuery('input[name="contact_'+$id+'_to"]').val().replace("*", "@"),
                    'name':jQuery('input[name="contact_'+$id+'_name"]').val(),
                    'email':jQuery('input[name="contact_'+$id+'_email"]').val(),
                    'content':jQuery('textarea[name="contact_'+$id+'_content"]').val()
                },function(data){
                    form.fadeOut('fast', function() {
                        jQuery(this).siblings('.success').show();
                    }).delay(3000).fadeIn('fast',function(){
						jQuery(this).find('textarea, input[type=text],input[type=email]').val('');
						jQuery(this).siblings('.success').hide();
						jQuery(this).siblings('.errors').hide();
					});
                });
                e.preventDefault();
            }
        });
    }

	/* portfolios preload */
	function portfolioInit($list){	
		jQuery($list).find('img').preload({
			onComplete:function(data){
				jQuery($list).find(".portfolio-item").each(function(i){
					jQuery(this).find(".overlay").removeClass('preload').addClass("image_overlay").html('');
				});
				if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 9) {
					jQuery($list).find("img").css("visibility", "visible");
				}else{
					jQuery($list).find("img").animate({"opacity": "1"}, "slow");
				}
				jQuery($list).find(".portfolio_image a").each(function(){
					enable_image_hover(jQuery(this));									
				});
			}
		});
	}
	function portfolioQuicksand(list,data,easing){
		list.quicksand(data,{
					duration: 800,
					easing:easing,
					enhancement:function(a){
						portfolioInit(a);
					},
					attribute: function(v) {
						return jQuery(v).attr('data-id');
					}
		},function(a){
			if (typeof Cufon != "undefined"){
				Cufon.refresh();
			}
			jQuery("a[rel^='prettyPhoto']").prettyPhoto({theme:themeParam,slideshow:5000,autoplay_slideshow:false});
		});
	}
	jQuery.preload("ul.portfolio-list img",{
		onComplete:function (data){
			jQuery("ul.portfolio-list .overlay:eq("+data.index+")").removeClass('preload').addClass("image_overlay").html('');
			if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 9) {
				jQuery("ul.portfolio-list img:eq("+data.index+")").css("visibility", "visible");
			}else{
				jQuery("ul.portfolio-list img:eq("+data.index+")").animate({"opacity": "1"}, "slow");
			}
			image = jQuery(".portfolio_image:eq("+data.index+")").find('a:first');
			enable_image_hover(image);
		},
		onFinish:function(){
			jQuery('.portfolios.sortable').each(function(){
				var $filter = jQuery(this).find('#portfolio-filter');
				var $section = jQuery(this);
				var $list = jQuery(this).find('ul.portfolio-list');
				var sortableType = jQuery($filter).attr('data-sortable');
				var quickeasing = $list.attr('data-easing');
				if(sortableType == 'all'){
					$filter.find('li a').click(function(){
						if(jQuery(this).hasClass('current'))
							return;
						$filter.find('li a').removeClass('current');
						jQuery(this).addClass('current');
						var listOpts = $filter.attr('data-options');
						var category = jQuery(this).attr('title');
						jQuery.post(
							window.location.href,
							{
								portfolioAction:'sortable',
								portfolioParams:listOpts,
								category:category
							},
							function(data, textStatus){
								$section.find('.portfolio-content').find('div.pagenavi').remove();
								if(jQuery(data).length > 1){
									jQuery(data).each(function(){	
										if(jQuery(this).is('.pagenavi'))
											$section.find('.portfolio-content').append(jQuery(this));
									});
								}
								portfolioQuicksand($list,jQuery(jQuery(data)[0]).find('li'),quickeasing);
							}
						);
					});
				}else{
					var $data = $list.clone();
					$filter.find('li a').click(function(){
						$filter.find('li a').removeClass('current');
						jQuery(this).addClass('current');
						var type = jQuery(this).attr('title');
						if(type == 'all')
							var $filteredData = $data.find('li');
						else
							var $filteredData = $data.find('li.'+type);
						portfolioQuicksand($list,$filteredData,quickeasing);
					});
				}
			});
		}
	});
	jQuery('.pagenavi.ajaxpage a').live('click',function(){
		var page = jQuery(this).attr('data-page');
		var cat = jQuery(this).attr('data-cat');
		var $section = jQuery(this).closest('.portfolios.sortable');
		var $list = jQuery($section ).find('ul.portfolio-list');
		var listOpts = $section.find('#portfolio-filter').attr('data-options');
		var quickeasing = $list.attr('data-easing');
		jQuery.post(
			window.location.href,
			{
				portfolioAction:'sortable',
				portfolioParams:listOpts,
				category:cat,
				portfoliopage:page
			},
			function(data, textStatus){
				if(jQuery(data).length > 1){
					jQuery(data).each(function(){
					if(jQuery(this).is('.pagenavi'))
						jQuery($section).find('.portfolio-content').find('div.pagenavi').html(jQuery(this).html());
					});
				}
				portfolioQuicksand($list,jQuery(data).find('li'),quickeasing);
				
			}
		);
	});
	/* imageframe preload */
	jQuery.preload(".image_frame img",{
		onComplete:function (data){
			jQuery(".image_frame .overlay:eq("+data.index+")").removeClass('preload').addClass("image_overlay").html('');
			if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 9) {
				jQuery(".image_frame:eq("+data.index+") img").css("visibility", "visible");
			}else{
				jQuery(".image_frame:eq("+data.index+") img").animate({"opacity": "1"}, "slow");
			}
			enable_image_hover(jQuery(".image_frame:eq("+data.index+") a"));
		}
	});
	/* gallery preload */
	jQuery.preload(".gallery-image-wrap img",{
		onComplete:function (data){
			jQuery(".gallery-image-wrap .overlay:eq("+data.index+")").removeClass('preload').addClass("image_overlay").html('');
			if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 9) {
				jQuery(".gallery-image-wrap:eq("+data.index+") img").css("visibility", "visible");
			}else{
				jQuery(".gallery-image-wrap:eq("+data.index+") img").animate({"opacity": "1"}, "slow");
			}
			enable_image_hover(jQuery(".gallery-image-wrap:eq("+data.index+")"));
		}
	});
	/* post feature preload */
	jQuery.preload(".post-image img",{
		onComplete:function (data){
			jQuery(".post-image span.overlay:eq("+data.index+")").removeClass('preload').html('');
			if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 9) {
				jQuery(".post-image img:eq("+data.index+")").css("visibility", "visible");
			}else{
				jQuery(".post-image img:eq("+data.index+")").animate({"opacity": "1"}, "slow");
			}
		}
	});


	/* sidebar */
	jQuery("#sidebar .current-cat a:first").addClass("first");
	jQuery("#sidebar .current_page_item a:first").addClass("first");
	jQuery(".right_sidebar #sidebar ul.children").each(function(){
		jQuery(this).find("a").each(function(){
			var left = jQuery(this).css("padding-left").replace("px","");
			left = parseInt(left) + 10;
			jQuery(this).css("padding-left",left+"px");
		});
	});
	jQuery(".left_sidebar ul.children").each(function(){
		jQuery(this).find("a").each(function(){
			var left = jQuery(this).css("padding-right").replace("px","");
			left = parseInt(left) + 10;
			jQuery(this).css("padding-right",left+"px");
		});
	});
	/*top line*/
	jQuery('.top a').click(function(){jQuery('html, body').animate({scrollTop:0}, 'slow');}); 
});
