// JavaScript Document

///*********** JQuery Action ***********///
///******* EFFECTS *********///

//CAROUSEL
function topmenu_pgCallback(carousel) {
	// BIND MENU TO CAROUSEL
	jQuery('.topmenu-carouselcontrol li').bind('click', function() {
		
        //carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('name')));
		var $curSelectNum = (parseInt(jQuery(this).attr('name'))-1);
		var $marginValue = $curSelectNum * -1010;
		jQuery('#main-carousel').stop().animate(
			{marginLeft:$marginValue},
			{duration:450});
        return false;
    });
};


// Initialize Carousel
jQuery(document).ready(function() {
	
	// Main Carousel
    jQuery("#main-carousel").jcarousel({
        scroll: 1,
        initCallback: topmenu_pgCallback,
		itemFallbackDimension: 900,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
	

	// Vertical Carousel
	
	
	jQuery('.topmenuarea a')

		.mouseover(function(){
		jQuery(this).stop().animate(
			{backgroundPosition:"(0px 0px)" },
			{duration:450})
	})
		.mouseout(function(){
		jQuery(this).stop().animate(
			{backgroundPosition:"(-41px -41px)"}, 
			{duration:450})
	})
	
	
	
});

///****** LOAD FUNCTION JCAROUSEL *********///
function startJquery($title){
	// Inner Carousel: Title
	var $carouselID = '#inner-carousel-' + $title;
	jQuery($carouselID).jcarousel({
        scroll: 4,
		start: 0,
		offset: 0
    });
	
	jQuery('.inner-carousel-holder li.odd')

		.mouseover(function(){
		jQuery(this).stop().animate(
			{backgroundColor:"#222222"},
			{duration:450})
	})
		.mouseout(function(){
		jQuery(this).stop().animate(
			{backgroundColor:"#101010"}, 
			{duration:450})
	})
	
	jQuery('.inner-carousel-holder li.even')

		.mouseover(function(){
		jQuery(this).stop().animate(
			{backgroundColor:"#222222"},
			{duration:450})
	})
		.mouseout(function(){
		jQuery(this).stop().animate(
			{backgroundColor:"#050505"}, 
			{duration:450})
	})
	
	// Main Carousel
	var $holderClass = '.' + $title + '-holder';
    jQuery($holderClass + " .inner-carousel-holder a").click(function(){
			jQuery($holderClass + " #verticalContentArea").animate(	
				{marginTop:"-520px"},
				{duration:450}
			)
			var $ajaxpageurl = jQuery(this).attr('href');
			jQuery($holderClass + " #vcontentDetailArea").load($ajaxpageurl + ' #ajaxcontentarea', function(){
				jQuery($holderClass + " #vcontentDetailArea .back-button a").click(function(){
					
					jQuery($holderClass + " #verticalContentArea").animate({
						marginTop:"0px",
						duration:450},
						function(){
							jQuery($holderClass + " #vcontentDetailArea").load('index.php?id=32');
					})
					return false;
    			});

			});
			return false;
    });
}




///******* STYLESHEET SWITCHING ***********///

(function($)
{
	jQuery(document).ready(function() {
		jQuery('.styleswitch').click(function()
		{
			switchStylestyle(this.getAttribute("rel"));
			return false;
		});
		var c = readCookie('style');
		if (c) switchStylestyle(c);
	});

	function switchStylestyle(styleName)
	{
		jQuery('link[@rel*=style][title]').each(function(i) 
		{
			this.disabled = true;
			if (this.getAttribute('title') == styleName) this.disabled = false;
		});
		createCookie('style', styleName, 365);
	}
})(jQuery);
// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}


///******** JS TO AS CONNECTOR *********///
function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window['ie_'+movieName] : document['ff_'+movieName];
}

function callToAS(str) 
{
	
	getFlashMovie("flashReader").sendToAS(str);
}

function sendToJS(val)
{
	document.getElementById('boxX').value = "ROM";
	document.getElementById('boxX').value = val;
}

///******** KEYPRESS DETECTOR *********///

//process this function whenever a key is pressed
jQuery(document).keypress(function (e) {

	//a & A
	if (e.keyCode == 65 || e.charCode == 65 || e.keyCode == 97 || e.charCode == 97){
		callToAS('all.0000');
	}

	//H & h
	if (e.keyCode == 104 || e.charCode == 104 || e.keyCode == 72 || e.charCode == 72){
		callToAS('hl.0000');
	}
	

});

///******** EXPANDING DIV CONTAINER *********////*


jQuery(document).ready(function() {})
function resizeDiv(adjustment){
	var browser = navigator.appName;
	var b_ver = navigator.appVersion;
	var $left_col = jQuery('#content_left').height();
	var $right_col = jQuery('#content_right').height();
	if( $left_col >= $right_col){
		var $content_h = $left_col;
	}else{
		var $content_h = $right_col;
	}
	var $home_content_h = $content_h;
	var $inner_h = $content_h + 300;
	var $outer_h = $inner_h + 200;
	if(browser == "Microsoft Internet Explorer"){
		jQuery('#content_right').height($content_h+adjustment)
		jQuery('#content_left').height($content_h)
		jQuery('#inner_wrap').height($inner_h);
		jQuery('#outer_btm_wrap').height($outer_h);
		jQuery('#outer_right_wrap').height($outer_h);
		jQuery('#outer_left_wrap').height($outer_h);
		jQuery('#outer_top_wrap').height($outer_h);
	}else{
		jQuery('#content_right').height($content_h+adjustment)
		jQuery('#content_left').height($content_h)
		jQuery('#home_content').height($home_content_h);
		jQuery('#inner_wrap').height($inner_h);
		jQuery('#outer_btm_wrap').height($outer_h);
		jQuery('#outer_right_wrap').height($outer_h);
		jQuery('#outer_left_wrap').height($outer_h);
		jQuery('#outer_top_wrap').height($outer_h);
	}

}


