/**
 * Common Javascript Methods
 *
 * @author 		Zone
 * @email		info@zonecontent.com
 * @url 		http://www.zonecontent.com/
 * @copyright 	Copyright (c) 2009, zonecontent.com. All rights reserved.
 * @version		0.0.1
 */
var CLASSES = {
	'focus' : 'focus',
	'hover' : 'hover'
};

// Submit hovers
$('#right-bar div.panel div.content div input.submit').hover(function() {
    $(this).attr({ src : '/static/img/common/button_submit_over.png'});
}, function() {
    $(this).attr({ src: '/static/img/common/button_submit.png' });
});
$('#main div.panel div.content div.blog-entry div.comments fieldset input.submit').hover(function() {
    $(this).attr({ src : '/static/img/common/button_post_comment_over.png'});
}, function() {
    $(this).attr({ src: '/static/img/common/button_post_comment.png' });
});
$('#main div.panel div.content div.competition-entry fieldset input.submit').hover(function() {
    $(this).attr({ src: '/static/img/common/button_submit_pink_over.png' });
}, function() {
    $(this).attr({ src: '/static/img/common/button_submit_pink.png' });
});

// Product hide/shows
$('#main.medium div.panel div.more-details div.synopsis').css('display', 'none');
$('#main.medium div.panel div.additional-details div.small p a.toggle').click(function() {
    if ($(this).text() == 'Show full synopsis +') {
        $(this).text('Hide full synopsis -');
        $('#main.medium div.panel div.more-details div.synopsis').css('display', 'block');
    } else {
        $(this).text('Show full synopsis +');
        $('#main.medium div.panel div.more-details div.synopsis').css('display', 'none');
    }
    return false;
});

$('#main.medium div.panel div.more-info ul li.hidden').css('display', 'none');
$('#main.medium div.panel div.more-info a.toggle').click(function() {
    if ($(this).text() == 'Show 3 more articles +') {
        $(this).text('Hide 3 articles -');
        $('#main.medium div.panel div.more-info ul li.hidden').css('display', 'block');
    } else {
        $(this).text('Show 3 more articles +');
        $('#main.medium div.panel div.more-info ul li.hidden').css('display', 'none');
    }
    return false;
});

// Specific classes
$('#navigation ol li div').parent().addClass('subnav');
if ($('#main.medium div.panel div.more-details').siblings('div.more-info').length > 0) {
    $('#main.medium div.panel div.more-details').addClass('more-details-thin');
}

// Region selector
$('#masthead div.region-search').addClass('java');
$('#masthead div.region-search p select').css('display', 'none');
$('#masthead div.region-search div.region').css('display', 'inline');

// Blog archive
$('#main div.panel div.content div.archive ul li a').click(function() {
    if ($(this).siblings('ul').length !== 0) {

        $(this).parent().toggleClass('active');
        return false;
    }
});

// Breadcrumb
if ($('#breadcrumb a.home').nextAll('a:first').hasClass('active')) {
    $('#breadcrumb a.home').after('<span class="home-right-preactive"></span>');
} else {
    $('#breadcrumb a.home').after('<span class="home-right"></span>');
}

// Textbox watermarks
$("#box-register-name").focus(function() {
    if ($(this).val() == 'Name') {
        $(this).val('');
    }
});
$("#box-register-name").blur(function() {
    if ($(this).val() === '') {
        $(this).val('Name');
    }
});
$("#box-register-email").focus(function() {
    if ($(this).val() == 'Email address') {
        $(this).val('');
    }
});
$("#box-register-email").blur(function() {
    if ($(this).val() === '') {
        $(this).val('Email address');
    }
});

// Vertically Align
(function ($) {
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	$(this).css('margin-top', mh);
	});
};
})(jQuery);
$('#blog-hero ul li a.thumb img, #blog-hero ul li a.thumb span').vAlign();
$('#blog-hero ul li a.thumb img').load(function() {
	$('#blog-hero ul li a.thumb img, #blog-hero ul li a.thumb span').vAlign();
});


// Internet Explorer
if ($.browser.msie && $.browser.version < 8) {

    // CSS3 Selectors
    $('#main div.panel div.content ul.list li:nth-child(even)').addClass('even');
    $('#right-bar div.panel div.content div ul li:last-child').addClass('last-child');

    $('#navigation > ol > li').hover(function() {

        if ($(this).hasClass('subnav')) {
            $(this).addClass('subnav_hover');
        }
        $(this).addClass(CLASSES.hover);
        $(this).children('div').css('display', 'block');

    }, function() {

        if ($(this).hasClass('subnav_hover')) {
            $(this).removeClass('subnav_hover');
        }
        $(this).removeClass(CLASSES.hover);
        $(this).children('div').css('display', 'none');

    });

    $('#bookshelf div.scroller ul li').hover(function() {

        $(this).addClass(CLASSES.hover);

    }, function() {

        $(this).removeClass(CLASSES.hover);

    });

    $('#masthead div.region-search div.region').hover(function() {
        
        $(this).addClass(CLASSES.hover);

    }, function() {

        $(this).removeClass(CLASSES.hover);

    });

    $('#bookshelf div.scroller ul li').hover(function() {
        
        $(this).addClass(CLASSES.hover);

    }, function() {

        $(this).removeClass(CLASSES.hover);

    });

    $('#masthead div.region-search div.region').hover(function() {

        $(this).addClass('region_hover');

    }, function() {

        $(this).removeClass('region_hover');

    });

    $('#main.medium div.panel div.product div.details div.border div.author').hover(function() {
        
        $(this).addClass('author_hover');

    }, function() {

        $(this).removeClass('author_hover');

    });

    // Auto Columns: http://welcome.totheinter.net/columnizer-jquery-plugin/
    $('div.az-list div').columnize({ columns: 3, lastNeverTallest: true });
    $('#content.atoz #main div.panel div.content').css('background', 'none');
    $('#content.atoz #main div.panel div.content').css('background', 'background:transparent url("../img/common/background_main_medium_body.png") repeat-y left top;');

}

// Internet Explorer 6
if ($.browser.msie && $.browser.version == 6) {

    $('#hero ul li.inactive div h3').each(function() {
        var h3pad = ($(this).parent().height() - $(this).height()) / 2;
        $(this).css('margin-top', h3pad + 'px');
    });

}
