/*
    File Name: script.js
    by Tolga Can
    RT-Theme 14
*/


/* CUFON FOTNS */
var cufon_fonts= 'true'; // true - false 
 
/* TWITTER */
var twitter_user_name = 'envatowebdesign'; //your twitter username 


//home page slider  
$(document).ready(function(){
   
	//Slide Backgrounds
	$('.slider_backgrounds li').each(function(){
		var background_file = $(this).find('img').attr("src");//background image
		var link =  $(this).find('a').attr("href");//slide link
		
		image_class = $(this).attr("class");
		var slide_image = '#fff url('+ background_file + ') no-repeat';	
		var this_slide = $('.background_image.'+image_class) ;
	
		if(link){
			this_slide.css({'background' : slide_image, 'cursor' : 'pointer'});
			this_slide.click(function(){
			    window.location = link;  
			});
		}else{
			this_slide.css('background',slide_image);
		}
	});
    
	var slider_area;
	var slider_buttons;

	// Which slider
	if ($('#slider_area').length>0){
		
		// Home Page Slider
		slider_area="#slider_area";	
		slider_buttons="#numbers";
	
		$(slider_area).cycle({ 
			fx:     'fade',  // Effect 
			timeout:  4000,  // Timeout value (ms) = 4 seconds
			easing: 'backout', 
			pager:  slider_buttons, 
			cleartype:  1,
			pause:           true,     // true to enable "pause on hover"
			pauseOnPagerHover: true,   // true to pause when hovering over pager link					
			pagerAnchorBuilder: function(idx) { 
				return '<a href="#" title=""><img src="images/pixel.gif" width="14" heigth="14"></a>'; 
			}
		});
		
	}   
		
	
});


//Product Detail Page - Image Slider
$(document).ready(function(){ 

	$('.product_slider').cycle({ 
	       fx:     'fade',  // Effect 
	       timeout:  4000,  // Timeout value (ms) = 4 seconds
	       easing: 'backout',
	       pager:  '.slider_buttons',
	       cleartype:  1,
	       pause:    true,     // true to enable "pause on hover"
	       pauseOnPagerHover: true,   // true to pause when hovering over pager link					
	       pagerAnchorBuilder: function(idx) { 
	       return '<a href="#" title=""><img src="images/pixel.gif" width="14" heigth="14"></a>'; 
	       }	    
	});
		
	
});


 
//pretty photo
jQuery(document).ready(function(){
        jQuery("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'light_rounded',slideshow:false,overlay_gallery: false});
});


//cufon fonts
if(cufon_fonts=='true') {
$(document).ready(function(){		
         
        Cufon.replace('h1,h2,h3,h4,h5,h6, #navigation > li > a', {
		hover: true,		  
		textShadow: '1px 1px #fff' 
        });
		 
		 
        Cufon.replace('.desc .title,.banner a.big_button span,  .head_text, .banner .text', {
                 hover: true
        });

        Cufon.replace('.banner .text', {
                hover: true 
        });
		 		 
        Cufon.replace('.desc .title,.cufon', {
                hover: true
        });

        Cufon.replace('.top_slogan, .top_slogan h4, .top_slogan h4 a', {
                 
                textShadow: 'none' 
        });
}); 
}	 

//buttons hover effect
$(document).ready(function(){		
	if(!$.browser.msie){     
	$('.small_button,.medium_button').hover(function(){
		$(this).stop().animate({opacity:'0.8'},{duration:500}  );
			  
	},function(){
		$(this).stop().css('opacity','1');
	});
	}
});


//Categories
$(document).ready(function(){		
	$('.portfolio_categories').click(function(){
		$('.portfolio_categories').hide(); 
		$('.portfolio_categories_open').stop().css({display:'block'});  
	});
	
	$('.portfolio_categories_open').click(function(){
		$('.portfolio_categories_open').hide(); 
		$('.portfolio_categories').stop().css({display:'block'});         
	}); 
}); 

//drop down menu
$(document).ready(function() {
	$("#navigation li").each(function()
	{
		$(this).hover(function()
		{
			$(this).find('ul:first').stop().css({
			      paddingTop:"8px",                              
			      height:"auto",
			      overflow:"hidden",
			      display:"none"
			      }).slideDown(200, function()
			{
			$(this).css({
			      height:"auto",
			      overflow:"visible"
			});
		});
		       
		},
		    
		function()
		{	
			$(this).find('ul:first').stop().slideUp(200, function()
			{	
			       $(this).css({
			       display:"none",
			       overflow:"hidden"
			       });
			});
		});	
	});
        
        $("#navigation ul ").css({
            display: "none"}
        ); 
});
 

// TABS - perform JavaScript after the document is scriptable.
$(function() {
	$("ul.tabs").tabs("> .pane", {effect: 'fade'});
	
	$(".accordion").tabs(".pane", {tabs: 'h3', effect: 'slide'});
	$(".scrollable").scrollable();
	
	
	$(".items.big_image img").click(function() {
	
		// see if same thumb is being clicked
		if ($(this).hasClass("active")) { return; }
		
		// calclulate large image's URL based on the thumbnail URL (flickr specific)
		var url = $(this).attr("src").replace("_t", "");
		
		// get handle to element that wraps the image and make it semi-transparent
		var wrap = $("#image_wrap").fadeTo("medium", 0.5);
		
		// the large image from www.flickr.com
		var img = new Image();
		
		
		// call this function after it's loaded
		img.onload = function() {
		
		// make wrapper fully visible
		wrap.fadeTo("fast", 1);
		
		// change the image
		wrap.find("img").attr("src", url);
		
		};
		
		// begin loading the image from www.flickr.com
		img.src = url;
		
		// activate item
		$(".items img").removeClass("active");
		$(this).addClass("active");
	
	// when page loads simulate a "click" on the first image
	}).filter(":first").click();

}); 


//search field function
$(document).ready(function() {
var search_text=jQuery(".search_bar .search_text").val();

	jQuery(".search_bar .search_text").focus(function() {
		jQuery(".search_bar .search_text").val('');
	});
});



//RT Portfolio Effect
$(document).ready(function() {


	$(window).load(function() {
		var portfolio_item=jQuery("a.imgeffect");
		
		portfolio_item.each(function(){
		
		var img_width = $(this).find('img').width();  
		var img_height = $(this).find('img').innerHeight();
		var imageClass = $(this).attr("class");
		$(this).prepend('<span class="imagemask '+imageClass+'"></span>');
		
		if($.browser.msie){
			var p = $(this).find('img');
			var position = p.position();
			var PosTop= parseInt(p.css("margin-top"))+position.top;
			var PosLeft= parseInt(p.css("margin-left"))+position.left;
			if (!PosLeft) {PosLeft= position.left}; 
				$(this).find('.imagemask').css({top: PosTop+2});
				$(this).find('.imagemask').css({left: PosLeft+2});
			}
		
			$('.imagemask', this).css({width:img_width,height:img_height,backgroundPosition:'right bottom'});
		
			if($.browser.msie){ $('.imagemask', this).css({display:'none'});}
		});
	});
	
	var image_e= $("a.imgeffect");
	
	if($.browser.msie){//ignore the shadow effect if browser IE
		$(this).find('.imagemask').css({display:"none"});
		
		image_e.mouseover(function(){
			$(this).find('.imagemask').stop().css({
			display:"block"
		}); 
		
		}).mouseout(function(){
			$(this).find('.imagemask').stop().css({
			display:"none"
			} );
		});
		
	}else{//real browsers :)
		image_e.mouseover(function(){
			$(this).find('.imagemask').stop().animate({
			display:"block", 
			opacity:1
		}, 0); 
		
		}).mouseout(function(){
			$(this).find('.imagemask').stop().animate({
			display:"none",
			opacity:0
			}, 0 );
		});                  
	}

});



 
 
//validate contact form
$(document).ready(function(){

      // show a simple loading indicator
      var loader = jQuery('<img src="images/loading.gif" alt="..." />')
              .appendTo(".loading")
              .hide();
      jQuery().ajaxStart(function() {
              loader.show();
      }).ajaxStop(function() {
              loader.hide();
      }).ajaxError(function(a, b, e) {
              throw e;
      });
      
      jQuery.validator.messages.required = "";
      var v = jQuery("#validate_form").validate({
              submitHandler: function(form) {
                      jQuery(form).ajaxSubmit({
                              target: "#result"
                      });
              }
      });
      
      jQuery("#reset").click(function() {
              v.resetForm();
      });
 });


//Slide to top
jQuery(document).ready(function(){
    jQuery(".line span.top").click(function() {
        jQuery('html, body').animate( { scrollTop: 0 }, 'slow' );
    });
});


//rounded corners
if($.browser.msie){
var curvyCornersNoAutoScan = true;
  window.onload = function() {
    var settings = {
      tl: { radius: 14 },
      tr: { radius: 14 },
      bl: { radius: 14 },
      br: { radius: 14 },
      antiAlias: true
    }

    var settings2 = {
      tl: { radius: 0 },
      tr: { radius: 14 },
      bl: { radius: 0 },
      br: { radius: 14 },
      antiAlias: true
    }
    
    var divObj = document.getElementById("myDiv");

    curvyCorners(settings, ".background_image,.content_background");
    curvyCorners(settings2, ".desc");
    
  }
}


//Tweets
$(document).ready(function(){
	if ($('.tweets').length>0){
		jQuery('.tweets').tweet({
			count: 3,
			query: 'from:'+twitter_user_name+'',
			loading_text: 'Loading Tweets...'
		});
	}
    
	if ($('.tweetbar').length>0){
		jQuery('.tweetbar').tweet({
			count: 1,
			query: 'from:'+twitter_user_name+'',
			loading_text: 'Loading Tweets...'
		});
	}    
});


//Social Media Icons
if(!$.browser.msie){
$(function() {
	$('.social_media_icons img').each(function() {
		$(this).hover(
			function() {
				$(this).stop().animate({ opacity: 1.0 }, 400);
			},
			function() {
				$(this).stop().animate({ opacity: 0.4 }, 400);
			})
		});
	});
}

//rounded images
if(!$.browser.msie){
	$(document).ready(function(){ 
		$(".frame img").imgr({radius:"8px 8px 8px 8px"});  
	});
}

//scroll 
$(document).ready(function(){
if ($('div.taps_wrap').length>0){	
	var settings = { 
		autoReinitialise: true,
		maintainPosition:false
	};
	var pane = $('div.taps_wrap .pane');
	pane.jScrollPane(settings);
}	
}); 


