var $j = jQuery.noConflict();

// QUICKSAND
$j(function() {
  var $filterType = $j('#filterOptions li.active a').attr('class');
  var $holder = $j('ul.ourHolder');
  var $data = $holder.clone();
	$j('#filterOptions li a').click(function(e) {
		$j('#filterOptions li').removeClass('active');
		var $filterType = $j(this).attr('class');
		$j(this).parent().addClass('active');
		
		if ($filterType == 'all') {
			var $filteredData = $data.find('li');
		} 
		else {
			var $filteredData = $data.find('li[data-type=' + $filterType + ']');
		}
		$holder.quicksand($filteredData, {
			duration: 800,
			easing: 'easeInOutExpo',
			enhancement: function() {
			  Cufon.refresh();
			  $j(".ourHolder .thumb a span").css({opacity: "0"});
			  $j("a[rel^='prettyPhoto']").prettyPhoto();
		   }
		});
		$holder.quicksand($filteredData, function(){
			  $j("a[rel^='prettyPhoto']").prettyPhoto();
			  Cufon.refresh();
			$j(".ourHolder .thumb a span").css({opacity: "0"});
			$j(".ourHolder .thumb a").hover(function(){
				$j(this).find('span').stop().animate({opacity: "1"});
				$j(this).find('img').stop().animate({opacity: "0.5"});
			},function(){
				$j(this).find('span').stop().animate({opacity: "0"});
				$j(this).find('img').stop().animate({opacity: "1"});
			});
		});
		return false;
	});
});


    // FADE HOVER EFFECT
    $j(function() {
        $j(".fadeover").hover(function() {
			$j(this).stop().animate({ opacity: '0.6'},130);
		},function() {
			$j(this).stop().animate({ opacity: '1'},130);
		});
    });
	
    $j(function() {
		$j(".thumb a span").css({opacity: "0"});
        $j(".thumb a").hover(function() {
			$j(this).find('span').stop().animate({opacity: "1"});
		},function() {
			$j(this).find('span').stop().animate({opacity: "0"});
		});
    });

	// Flickr fade animation
	$j(function(){
		$j(".flickr_stream img").hover(function(){
			$j(".flickr_stream img").stop().animate({opacity: "0.2"});
			$j(this).stop().animate({opacity: "1"});
		},function(){
			$j(".flickr_stream img").stop().animate({opacity: "1"});
		});
	});

	// PORTFOLIO HOVER SPAN
	$j(function(){
		$j(".ourHolder .thumb a span").css({opacity: "0"});
		$j(".ourHolder .thumb a").hover(function(){
			$j(this).find('span').stop().animate({opacity: "1"});
			$j(this).find('img').stop().animate({opacity: "0.5"});
		},function(){
			$j(this).find('span').stop().animate({opacity: "0"});
			$j(this).find('img').stop().animate({opacity: "1"});
		});
	});

	// Tag list menu
	$j(function(){
			$j('.entry-tags ul').hide();
		$j(".entry-tags span").hover(function(){
			$j(this).find('ul').stop().show();
		},function(){
			$j(this).find('ul').stop().hide();
		});
	});
	
	// Recent post bug in firefox fix
	$j(function(){
		$j(".gecko .recent_posts_small_sidebar").parent('.widget_lightbg').addClass('widget_firefox');
	});

    // DROPDOWN MENU
    $j(function() {
        $j("#main-menu ul > li").hover(function() {
			$j(this).find(".sub-menu:first").slideDown(120).parent().find("a").addClass("hover");
			$j(this).find('ul:first').parent().find('a').removeClass("hover");
			var arrowed = $j(this).find("li:has(ul)");
			$j(this).find(arrowed).addClass("subber");
		},function() {
			$j(this).find(".sub-menu:first").slideUp(70).parent().find("a").removeClass("hover");
		});
    });


    // SIDEBAR LIST link move
    $j(function() {
        $j(".sub-menu li").hover(function() {
			$j(this).find("a:first").stop().animate({ paddingLeft: '20px'},130);
		},function() {
			$j(this).find("a:first").stop().animate({ paddingLeft: '10px'},130);
		});
    });
    // SIDEBAR LAST MARGIN RESET
    $j(function() {
        $j(".recent_posts_small_sidebar li:last").css('margin-bottom','0px');
    });
	

    // SINGLE SLIDER THUMBNAILS DISPLAY BIG IMAGES
    $j(function() {
		$j(".thumbnail_link").click(function() {
			var mainImage = $j(this).attr("rel"); //Find Image Name
			var mainTitle = $j(this).attr("title"); //Find Image Name
			
			$j("#big_size_viewer img").animate({'opacity' : 0},600, 'easeInOutExpo', function(){
				$j("#big_size_viewer").html('<a href="'+mainTitle+'" rel="prettyPhoto[Gallery]"><img src="'+mainImage+'" alt="" /></a>').hide().fadeIn();
				$j("a[rel^='prettyPhoto']").prettyPhoto();
			});
		   
		   
			return false;		
		});
    });
	
	// ----------------------------------------------------------------------------------------------------------------------------
	// Item Slider

	 $j(function() {
			$j('.item_name').html($j('.carousel_ul li:eq(0) a').attr('title'));
	  });
	 $j(function() {
			
			var auto_slide = 1;
			var hover_pause = 1;
			var key_slide = 1;
		
			var auto_slide_seconds = 5000;
			
			
			$j('.carousel_ul li:first').before($j('.carousel_ul li:last')); 
			
			if(auto_slide == 1){
				var timer = setInterval('slide("right")', auto_slide_seconds); 
			}
	  
			if(hover_pause == 1){
				$j('.carousel_ul').hover(function(){
					clearInterval(timer)
				},function(){
					timer = setInterval('slide("right")', auto_slide_seconds); 
				});
	  
			}
	  
			if(key_slide == 1){
				$j(document).bind('keypress', function(e) {
					if(e.keyCode==37){
							slide('left');
					}else if(e.keyCode==39){
							slide('right');
					}
				});
	
			}
			
			
	  });
	
	function slide(where){
		
		var item_width = $j('.carousel_ul li').outerWidth();
		
		if(where == 'left'){
			var left_indent = parseInt($j('.carousel_ul').css('left')) + item_width;
		}else{
			var left_indent = parseInt($j('.carousel_ul').css('left')) - item_width;
		
		}
		
			$j('.item_name').fadeOut(30);
		$j('.carousel_ul:not(:animated)').animate({'left' : left_indent},800, 'easeInOutExpo', function(){ 
			if(where == 'left'){
				$j('.carousel_ul li:first').before($j('.carousel_ul li:last'));
			}else{
				$j('.carousel_ul li:last').after($j('.carousel_ul li:first')); 
			}
			
			$j('.item_name').html($j('.carousel_ul li:eq(1) a').attr('title')).delay(300).fadeIn(150);
			$j('.carousel_ul').css({'left' : '-240px'});
			
		});
		   
	}
	
	// ----------------------------------------------------------------------------------------------------------------------------
// Captcha system
$j(function(){
$j("#submitter input").css({opacity: "0.5"}).attr('disabled', true);
$j("#errorcaptcha").css({opacity: "0"});
$j("#check").keyup(function () {
		var rep = $j(this).val();
		var n1 = document.getElementById('num1').innerHTML;
		var n2 = document.getElementById('num2').innerHTML;
		var n3 = parseInt(n1) * parseInt(n2);
      		if( n3 == rep ){
			$j("#submitter input").removeAttr("disabled").animate({opacity: "1"},{duration:150});
			$j("#errorcaptcha").text(" ").animate({opacity: "0"},{duration:150});
		}
		else {
			$j("#errorcaptcha").text("Try again...").animate({opacity: "1"},{duration:350});
			$j("#submitter input").attr('disabled', true).animate({opacity: "0.5"},{duration:150});
		}
    });
});



// ----------------------------------------------------------------------------------------------------------------------------
/* begin contact form */
$j(function(){
	$j('#list').hide();
	var form = $j("#contact-form");
	var name = $j("#namehis");
	var email = $j("#email");
	var subject = $j("#subject");
	var message = $j("#comment");
	var check = $j("#check");
	
	
	var inputs = form.find(":input").filter(":not(:submit)").filter(":not(:checkbox)").filter(":not([type=hidden])").filter(":not([validate=false])");

	form.submit(function(){
		if(validateEmail()){
			
			var $name = name.val();
			var $email = email.val();
			var $subject = subject.val();
			var $message = message.val();
			
			$j.ajax({
				type: 'GET',
				url: document.getElementById('url_site').innerHTML+"send_mail.php",
				data: form.serialize(),
				success: function(ajaxCevap) {
					$j('#list').hide();
					$j('#list').html(ajaxCevap);
					$j('#list').fadeIn("normal");
					$j('#list').delay(2000).fadeOut("normal");
					name.attr("value", "");
					email.attr("value", "");
					subject.attr("value", "");
					message.attr("value", "");
					check.attr("value", "");
					$j("#submitter input").attr('disabled', true).animate({opacity: "0.5"},{duration:150});
					var randomnumber=Math.floor(Math.random()*11);
					var randomnumber2=Math.floor(Math.random()*11);
					$j("#num").html(randomnumber);
					$j("#num2").html(randomnumber2);
				}
			});

			return false;
		}else{
			return false;
		}
	});
	
	function validateEmail(){
		var a = $j("#email").val();
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
		if(filter.test(a)){
			return true;
		}
		else{
			return false;
		}
	}
		
});
/* end contact form */






		// ----------------------------------------------------------------------------------------------------------------------------
	// TESTIMONIAL
	jQuery(document).ready(function(){
		showing = jQuery('#rotating_items div.rotating_item:first'); // Initiate the 'showing' variable as the first rotating_item
		showing.siblings('div').hide(); // Hide all other rotating_items
		setInterval("show_next_rotating_item(showing)", 5000); // Set the rotate time to 5 seconds
	});
	 
	// Below is the code that picks an item at random to display
	jQuery.jQueryRandom = 0;
	jQuery.extend(jQuery.expr[":"],
	{
		random: function(a, i, m, r) {
			if (i == 0) {
				jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
			};
			return i == jQuery.jQueryRandom;
		}
	}); 
	 
	// The below function repeatedly gets called, to do the rotating
	function show_next_rotating_item(t){
		jQuery(t).fadeOut(30);
	 	
		var next_rotating_item = jQuery(t).siblings('.rotating_item:random');
		if(!next_rotating_item.attr('class')){
			next_rotating_item = jQuery('#rotating_items div.rotating_item:first');
		}	
		next_rotating_item.fadeIn(400);
	 
		showing = next_rotating_item;
		var testi_height = $j(next_rotating_item).height(); 
		$j("#rotating_items").animate({height: testi_height});
	}
	
	

// JQUERY SHORTCODES ANIMATIONS
// Tabs
$j(function() {
		
        $j('.the_tabs div').hide();
		$j(".tabs a:first").addClass("selected");
		$j(".tabs_table").each(function(){
			$j(this).find('.the_tabs div:first').show();
			$j(this).find('a:first').addClass("selected");
		});
	
		$j('.tabs a').click(function(){
			var which = $j(this).attr("rel");
			$j(this).parents(".tabs_table").find(".selected").removeClass("selected");
			$j(this).addClass("selected");
			$j(this).parents(".tabs_table").find(".panes").find("div").hide();
			$j(this).parents(".tabs_table").find(".panes").find("#"+which).fadeIn(800);
		});
 
});

// Slider
$j(function() {

	//Set Default State of each portfolio piece
	$j(".paging").show();
	$j(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $j(".window").width();
	var imageSum = $j(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$j(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$j(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$j(".image_reel").animate({ 
			left: -image_reelPosition
		}, { "duration": 400, "easing": "easeInOutExpo" } );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $j('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $j('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 7000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$j(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$j(".paging a").click(function() {	
		$active = $j(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
	
});

//Accordion
$j(function() {
	
	$j('.accordionButton').click(function() {

		$j('.accordionButton').removeClass('on');
		  
	 	$j('.accordionContent').slideUp(200);
   
		if($j(this).next().is(':hidden') == true) {
			
			$j(this).addClass('on');
			  
			$j(this).next().slideDown(200);
		 } 
		  
	 });
	
	$j('.accordionButton').mouseover(function() {
		$j(this).addClass('over');
		
	}).mouseout(function() {
		$j(this).removeClass('over');										
	});
	$j('.accordionContent').hide();

});


//Toggle
$j(function(){
	$j('.hidden').css("display", "none");
	$j(".toggler h4").hover(function() {
		$j(this).css("cursor","pointer").css("color","#999999");
	},function() {
		$j(this).css("color","#181818");
	});
	$j(".toggler h4").click(function() {
		$j(this).parent().children('.hidden').slideToggle(200);
		$j(this).toggleClass("plus_minus");
	});
});

// ----------------------------------------------------------------------------------------------------------------------------
// 
$j(function(){
 
    $j('a[href*=#]').click(function() {
 
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
 
            var $target = $j(this.hash);
 
            $target = $target.length && $target || $j('[name=' + this.hash.slice(1) +']');
 
            if ($target.length) {
 
                var targetOffset = $target.offset().top;
 
                $j('html,body').animate({scrollTop: targetOffset}, 600);
 
                return false;
 
            }
 
        }
 
    });
 
});
// ----------------------------------------------------------------------------------------------------------------------------
// Go Top Link Appear
$j(function() {
	$j(".go_top").css("display","none");

	$j(window).scroll(function() {
		if ($j(this).scrollTop() <= 200) {
			$j(".go_top:visible").fadeOut();
		}
		else {
			$j(".go_top:hidden").fadeIn();
		}
	});

});
