/*-------------------------------------------------------------------------
=GLOBAL FUNCTIONS
-------------------------------------------------------------------------*/
$(document).ready(function() {
	
	$('ul#photosList li a').fancybox(); // run fancybox for images
	
	$('a.thumb, a#watchRandom, a#teaser').fancybox({'centerOnScroll': false}); // run fancybox for trailers
	
    $("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 unfocus 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() { // check input box
        if ($("div#search input").val() == "Aranacak terimi giriniz...") {
            alert("Lütfen aranacak terimi giriniz...");
			$("div#search input").focus();
			return false;
        }
    });
    
	$("a#showHide").click(function() { // show/hide tags
			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() { // show/hide tabs - thanks for this code snippet erhan ;) @eburhan.com
        
        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
    
    $('div#featured ul li a, div#incomingMovies ul li a').hover(function() {
    	$(this).children('span').animate({bottom:0},{queue:false, duration:150});
    }, function() {
    	$(this).children('span').animate({bottom:'-24px'},{queue:false, duration:350});
    });
    
    $('a#watchRandom').click(function() { // open random trailer
    	var random = Math.floor(Math.random() * $('ol#trailerSources li').length);
		var sourceURL = $('ol#trailerSources li:not(:empty)').eq(random).text();
		if ( $.browser.msie && Math.floor($.browser.version) > 7 || !$.browser.msie ) {
			var replace = $('div#randomTrailer object embed').attr('flashvars').replace(/(http|https):\/\/(.)+flv/g, sourceURL);
    		$('div#randomTrailer object embed').attr('flashvars', replace);
		}
    	if ( $.browser.msie > 7 ) {
    		$('div#randomTrailer object').append('<param name="flashvars" value="'+ sourceURL +'&amp;height=340&amp;width=560&amp;autostart=true&amp;displayheight=340&amp;displayNav=false&amp;showicons=true&amp;backcolor=0x000000&amp;frontcolor=0xCCCCCC&amp;lightcolor=0x557722"></param>');
		}
		/*if ( $.browser.msie < 8 ) {
			$('div#randomTrailer').append('<param name="flashvars" value="'+ sourceURL +'&amp;height=340&amp;width=560&amp;autostart=true&amp;displayheight=340&amp;displayNav=false&amp;showicons=true&amp;backcolor=0x000000&amp;frontcolor=0xCCCCCC&amp;lightcolor=0x557722"></param>')
		}*/

    });
    
    $('div.incomingMovies ul li a').hover(function(){
    	$(this).children('img').animate({left:'7px', top:'5px', width:'55px', height:'55px'},{queue:false, duration:250});
    }, function() {
    	$(this).children('img').animate({left:'10px', top:'8px', width:'50px', height:'50px'},{queue:false, duration:150});
    });
    
    if ( $('body').hasClass('ie6') ) {
    	DD_belatedPNG.fix('div#center, a#teaser span, div#tv, a#watchRandom');
    	
    	$('a#watchRandom').hide();
    	
    	$('div#tv').hover(function() {
    		$('a#watchRandom').show();
    	}, function() {
    		$('a#watchRandom').hide();
    	});
    };
    
});



/*-------------------------------------------------------------------------
=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() {
	if ($('div.entry_read').hasClass('single')) {
		var addthis_config = {  data_use_flash: false }
		
	    $("ul#photosList").jcarousel({
	        buttonNextHTML: "",
	        buttonPrevHTML: "",
	        scroll: 1,
	        visible:4,
	        initCallback: photoCarousel
	    });
	}
});



/*-------------------------------------------------------------------------
=ARCHIVE LIST
-------------------------------------------------------------------------*/	
$('ul#archive_posts').ready(function() {
	if ( !$('body').hasClass('ie6') ) {
		
		var limit = 9;
		$('ul#archive_posts li:gt(' + limit + ')').hide();
		$('ul#archive_posts li:visible:last').addClass('last');
		$('ul#archive_posts').after('<a href="javascript:;" id="continue">Devam Et</a>');
	
		$('a#continue').click(function() {
			limit = limit + 11;
			$('ul#archive_posts li:lt(' + limit + ')').slideDown("slow");
			$('html').animate({scrollTop: $(this).offset().top -50}, 1000);
			
			if ($('ul#archive_posts li').length <= limit) {
				$(this).remove();
			}
			else {
				$('ul#archive_posts li:visible:last').addClass('last');
			}
		});
		
	}
});
