
$(document).ready(function (){
	init();
});

var current = null;
var move = null;
var pos = null;
var n_tabs = 5;
var tab_names = new Array('info', 'lenses', 'frames', 'second', 'glasses')

function init() {
	var d_h = $('#display_body').height();
	var b_h = (d_h-200)/2;
	$('.arrow_holder').css('margin-top', b_h);
	
	
	current = 1;
	move = $('#scrollHolder .content').width()+60;
	pos = $('#scrolllHolder').css('x');
	switcher(current);
}

function tabClick(n) {
	switcher(n);
}

function arrowClick(d) {
	if(d == 'left' && current-1 > 0) {
		switcher(current-1);
	}
	if(d == 'right') {
	    if (current+1 <= n_tabs) {
		    switcher(current+1);
		}
		else {
		    location.hash = '#actions';
		}
    }
}

function switcher(n) {
	var t = $('#'+tab_names[n-1]);
	$('#tabs ul li a').each(
		function (intIndex) {
			$(this).css('background-position', 'center top');
			$(this).mouseover(function(){
				$(this).css('background-position', 'center center');
			});
			$(this).mouseout(function(){
				$(this).css('background-position', 'center top');
			});
		}
	);
	t.unbind();
	t.css('background-position', 'center bottom');
	if(n === 1) {
		$('#arrow_left').fadeOut();
		$('#arrow_right').fadeIn();
	}
	if(n > 1 && n < n_tabs) {
		$('#arrow_right').fadeIn();
		$('#arrow_left').fadeIn();
	}
	if(n === n_tabs) {
		//$('#arrow_right').fadeOut();
		$('#arrow_left').fadeIn();
	}
	current = n;
	slide();
}

function slide() {
	$('#scrollHolder').animate({left: (current-1)*move*-1}, 500);
}

function OpenWindow(strMyPage, strMyName, intW, intH, strScroll, strResize, strMenu) {
    var intWinL = ((screen.width - intW) / 2);
    var intWinT = ((screen.height - intH) / 2);
    var strWinProps = 'height='+intH+',width='+intW+',top='+intWinT+',left='+intWinL+',scrollbars='+strScroll+',resizable='+strResize+',menubar='+strMenu;
    var objWin = window.open(strMyPage, strMyName, strWinProps);
    
    if (parseInt(navigator.appVersion) >= 4) {
        objWin.window.focus(); 
    }

    return objWin;
}

