﻿/// <reference path="~/assets/scripts/generic/jquery-1.4.2.min.js" />
/***
	INIT JAVASCRIPT

    The purpose of this script is to perform any tasks that are required on all pages in the site.

    @Authors
    Graham Licence

***/
$j = jQuery.noConflict();  
$j(document).ready(function() {
	/*$("body").click(function(event) {
		if ($(event.target).is('a') || $(event.target).parent('a').size() > 0) {
			var anchor;
			if ($(event.target).is('a')) {
				anchor = $(event.target);
			}
			else {
				anchor = $(event.target).parent('a');
			}
			if (anchor[0].hostname !== location.hostname &&  !($(anchor).hasClass('internal'))) {
				window.open(anchor[0].href);
				return false;
			}
		}
    });*/
    // add "opens in new window" to external links 
	/*$("a[href*='http']:not([href*='"+location.hostname+"'])").each(
	    function() {
	        var title = $(this).attr("title");
	        var titleNewWindow = title + ", opens in a new window";
	        $(this).attr("title", titleNewWindow);
		});*/

	// navigation
	jQuery.easing.def = "easeInOutBounce";
	/*$("#navigation ul li").hover (
	    function() {
	        var litag = $(this).parent("li");
	        var atag = $(this);
	        litag.stop();
	        atag.stop();
	        $("<div></div>").css({ left: 0 }).animate({ left: "10" }, { duration: 100, step: stepTogether, easing: "easeOutQuad"});

            function stepTogether(step) {
                var val1 = Math.round(step); //0->10
                var val2 = 10 - val1;//10->0
                try {
                    litag.css({backgroundPosition: val1 + "px " + val2 + "px"});
                }
                catch(Error){
                }
                atag.css({marginTop: (3 + val2) + "px" ,marginLeft:(40 + val1) + "px"}); 
            }
	    },
	    function() {
	        var litag = $(this).parent("li");
	        var atag = $(this);
	        litag.stop();
	        atag.stop();
	        $("<div></div>").css({ left: 10 }).animate({ left: "0" }, { duration: 300, step: stepTogether, easing: "easeInQuad"});
	              
            function stepTogether(step) {
                var val1 = Math.round(step); //0->10
                var val2 = 10 - val1;//10->0
                try {
                    litag.css({backgroundPosition: val1 + "px " + val2 + "px"});
                }
                catch(Error) {
                }
                atag.css({marginTop: (3 + val2) + "px" ,marginLeft:(40 + val1) + "px"});
            }
	    }
	);*/
	
	//cúfon
	
	Cufon.replace('#topcontent h2', {
		hover:true,				
		fontFamily: 'Burst My Bubble'	
	});
	Cufon.replace('.post h1', {
		hover:true,				
		fontFamily: 'Futura Condensed Medium'	
	});
	
	
   // day/night background image
    //$j('body').removeClass('day');
        var dateMonth = new Date().getMonth();
        var dateHour = new Date().getHours();
        if (dateMonth <= 5) { 
            nightHour = 17
        } else if (dateMonth <= 9) { 
            nightHour = 20
        } else if (dateMonth <= 12) { 
            nightHour = 16
        } if (dateHour >= nightHour) {
            $j('body').removeClass('day').addClass('night');
        }
        else {
            $j('body').removeClass('day').addClass('today');
        }
    
    // add class for different backgrounds on posts view    
    $j('.posts .post:eq(0)').addClass('one');
    $j('.posts .post:eq(1)').addClass('two');
    $j('.posts .post:eq(2)').addClass('three');
    $j('.posts .post:eq(3)').addClass('four');
    $j('.posts .post:eq(4)').addClass('five');
    $j('.posts .post:eq(5)').addClass('six');
    $j('.posts .post:eq(6)').addClass('seven');
    $j('.posts .post:eq(7)').addClass('eight');
    $j('.posts .post:eq(8)').addClass('nine');
    
    // define previous and next posts
    $j('#postnavigation a[title^="Previous"]').addClass('previous');
    $j('#postnavigation a[title^="Next"]').addClass('next');
    
    // show/hide comments
    $j('#commentlist, #comment').addClass('hidden').removeAttr('style');
    $j('.post .footer a, #comment').click(function() {
        $('#commentlist, #comment').removeClass('hidden');
    });
    
    $j('.commentForm').hover(function() { 
       $j(this).addClass('hover');
    }, function() {
        $j(this).removeClass('hover');
    });
    $j('.commentForm label, .commentForm input, .commentForm #commentCompose, .commentForm .bbcode').hide();
    $j('.commentForm').click(function() {
        $j('.commentForm label, .commentForm input, .commentForm #commentCompose, .commentForm .bbcode').show('normal');
    });
    
    // add link to cartoon on homepage
    var pageName = location.href;
    
    if (pageName == 'http://www.grahamlicence.co.uk/') {
	    geturl();
	} else if (pageName == 'http://www.grahamlicence.co.uk/default.aspx') {
	    geturl();
	}
	
	//add url to cartoon
	function geturl() {
	    //$('.post')[0]
	 /*   $('.post').each(function() {
	        var postLink = $(this)('.post h1 a').attr('href');
	        var postUrl = $('<a href="' + postLink + '"></a>');
	        $('.postcontent .text img').wrap(postUrl);
	        event.stopPropagation();
	    });
	*/
	
	    var postLinkOne = $j('.one h1 a').attr('href');	
	    var postLinkOneUrl = $j('<a href="' + postLinkOne + '">' + '</a>');
	    $j('.one .postcontent .text img').wrap(postLinkOneUrl);
	    
	    var postLinkTwo = $j('.two h1 a').attr('href');	
	    var postLinkTwoUrl = $j('<a href="' + postLinkTwo + '">' + '</a>');
	    $j('.two .postcontent .text img').wrap(postLinkTwoUrl);
	    
	    var postLinkThree = $j('.three h1 a').attr('href');	
	    var postLinkThreeUrl = $j('<a href="' + postLinkThree + '">' + '</a>');
	    $j('.three .postcontent .text img').wrap(postLinkThreeUrl);
	    
	    var postLinkFour = $j('.four h1 a').attr('href');	
	    var postLinkFourUrl = $j('<a href="' + postLinkFour + '">' + '</a>');
	    $j('.four .postcontent .text img').wrap(postLinkFourUrl);
	    
	    var postLinkFive = $j('.five h1 a').attr('href');	
	    var postLinkFiveUrl = $j('<a href="' + postLinkFive + '">' + '</a>');
	    $j('.five .postcontent .text img').wrap(postLinkFiveUrl);
	    
	    var postLinkSix = $j('.six h1 a').attr('href');	
	    var postLinkSixUrl = $j('<a href="' + postLinkSix + '">' + '</a>');
	    $j('.six .postcontent .text img').wrap(postLinkSixUrl); 
	};    
});
