/*
  _   _   _   _   _   _   _   _   _   _   _   _  
 / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ 
( X | H | T | M | L | K | I | T | C | H | E | N )
 \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ 
 
http://www.xhtmlkitchen.com

Client:		Sinemalardan - http://www.sinemalardan.com
Author: 	Fatih Turan
Last-Edit: 	11:41 18.02.2009

*/

/*-------------------------------------------------------------------------
=GLOBAL FUNCTIONS
-------------------------------------------------------------------------*/
$(document).ready(function() {
	
    $("div#search input").focus(function() { //on focus at search
        $("div#search").css({backgroundPosition:"0 -51px"});
        if ($("div#search input").val() == 'Aranacak terimi giriniz...') {
            $("div#search input").val("");
        }
    });
    
    $("div#search input").blur(function() { //on focus at search
        $("div#search").css({backgroundPosition:"0 0"});
        if ($("div#search input").val() == '') {
            $("div#search input").val("Aranacak terimi giriniz...");
        }
    });
	
    $("div#search button").click(function() { 
        if ($("div#search input").val() == "Aranacak terimi giriniz...") {
            alert("Lütfen aranacak terimi giriniz...");
			$("div#search input").focus();
			return false;
        }
    });
    
	$("a#showHide").click(function() {
			if ($("div#postTags").css("overflow") == "hidden") {
				$("a#showHide").css({backgroundPosition: "0 -16px"});
				$("div#postTags")
					.css({overflow: "visible"})
					.css({height: "auto"});
			} 
			else {
				$("a#showHide").css({backgroundPosition: "0 0"});
				$("div#postTags")
					.css({overflow: "hidden"})
					.css({height: 21});	
			 }
	});

    $("ul.tabs li a").click(function() { //tabs
        
        var thisDiv = $(this).parent().parent().parent();

        $(".tabContent:not(:hidden)", thisDiv).hide();

        $("ul.tabs li a", thisDiv).removeClass('active_tab');			
        $(this).addClass('active_tab');

        var Attr = $(this).attr('rel');
        $('.' + Attr).show();

    });
    
    $("div#subscription a").click(function() { //subscription sliding effect
        $("div#subscribing_type").slideToggle("normal");
        return false;
    });
    
    $("div#subscribing_types form").attr("target", "popupwindow") //add target attribute for w3c standards
   
	function filterPath(string) {
	return string
	  .replace(/^\//,'')
	  .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
	  .replace(/\/$/,'');
	}
	
	$('a[href*=#]').each(function() {
	if ( filterPath(location.pathname) == filterPath(this.pathname)	&& location.hostname == this.hostname && this.hash.replace(/#/,'') ) {
		var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
		var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
		if ($target) {
		 var targetOffset = $target.offset().top;
		 $(this).click(function() {
		   $('html, body').animate({scrollTop: targetOffset}, 400);
		   return false;
		 });
		}
	}
	});
	
	$("a#friendfeed").click(function(){
		var e=document.createElement('script');
		e.setAttribute('type','text/javascript');
		e.setAttribute('src','http://friendfeed.com/share/bookmarklet/javascript');
		document.body.appendChild(e);
		return false;
	});    
});

$("a#teaser").ready(function() {
	$("a#teaser").mouseover(function() {
		$(this).children("img").css({opacity: .5});
	});
	
	$("a#teaser").mouseout(function() {
		$(this).children("img").css({opacity: 1});
	});
});

$("ul#share").ready(function() {
	$("ul#share a").attr("target", "_blank");
});



/*-------------------------------------------------------------------------
=PHOTO CAROUSEL
-------------------------------------------------------------------------*/	
function photoCarousel(carousel) {
    $("a#photosNext").bind('click', function() {
        carousel.next();
        return false;
    });

    $("a#photosPrev").bind("click", function() {
        carousel.prev();
        return false;
    });
};

$("div#photos").ready(function() {
    $("ul#photosList").jcarousel({
        buttonNextHTML: "",
        buttonPrevHTML: "",
        scroll: 1,
        visible:4,
        initCallback: photoCarousel
    });
});



/*-------------------------------------------------------------------------
=IN THEATHERS
-------------------------------------------------------------------------*/	
$('div#inTheaters').ready(function() {
	$('div#inTheaters h3').after('<div id="scrollControls">	<a href="javascript:;" id="down">Aşağı</a><a href="javascript:;" id="up">Yukarı</a></div>');
	// $('div#inTheaters span').before('<div id="openClose"><a href="#">Gizle</a></div>');
	
	$('ul.links li:first').addClass('selected');
	
	var order = 0;
	
	function down() {
		if (order < 5) {
			$('a.bigThumb img').attr('src', $('li.selected').next('li').children('img').attr('src'));
			$('li.selected').removeClass().next('li').addClass('selected');
			$('div#inTheaters h3 a').text($('li.selected a').text()).attr('href', $('li.selected a').attr('href'));
			$('a.bigThumb').attr('href', $('li.selected a').attr('href'));
			order++;
		}
		if (order == 5) {
			function reset() {
				$('a.bigThumb img:first').attr('src', $('ul.links li:first').children('img').attr('src'));
				$('li.selected').removeClass();
				$('ul.links li:first').addClass('selected');
				$('div#inTheaters h3 a').text($('ul.links li:first a').text()).attr('href', $('ul.links li:first a').attr('href'));
				$('a.bigThumb').attr('href', $('ul.links li:first a').attr('href'));
				order = 0;
			}
			setTimeout(reset, 2000);
		}
	}
	
	function up() {
		if (order > 0) {
			$('a.bigThumb img').attr('src', $('li.selected').prev('li').children('img').attr('src'));
			$('li.selected').removeClass().prev('li').addClass('selected');
			$('div#inTheaters h3 a').text($('li.selected a').text()).attr('href', $('li.selected a').attr('href'));
			$('a.bigThumb').attr('href', $('li.selected a').attr('href'));
			order--;
		}
	}
	
	$('a#down').click(function() {	down();	});	
	
	$('a#up').click(function() { up();	});
	
	// var autoShow = setInterval(down, 2000);
	// 
	// $('div#inTheaters *').hover(
	// 	function () {
	// 		clearInterval(autoShow);
	// 	},
	// 	function () {
	// 		var autoShow = setInterval(down, 2000);
	// 	}
	// );
	
});