﻿var $hmcp = jQuery.noConflict();
var hmcpLink = "#";

$hmcp(document).ready(hmcp_READY);
var $go_button_location = "#gem-help-me-choose-lightbox > div > .information-go-container > .arrow-right-button";

function hmcp_READY(){	
	var firstContainer = $hmcp('#first-container');
	$hmcp('#gem-help-me-choose-lightbox > div > [step=first]').appendTo(firstContainer);
	$hmcp('#gem-help-me-choose-lightbox > div > [step=first]').show();
	hmcp_BIND_EVENTS();
	$hmcp( $go_button_location ).hide();
}

function hmcp_BIND_EVENTS() {
	$hmcp('.box-content > ul > li').click(option_CLICK);
}

function option_CLICK(e) {
	var currentStep = $hmcp(this).parents('.box-content').attr('step');
	var clickedRef = $hmcp(this).attr('id');
	var showGoBtn = false;
		
	if (currentStep == 'first') {
		$hmcp('.box-content > ul > li').removeClass('selected');
		$hmcp('.solid-plus-right-button').removeClass('selected');
		var newStep = $hmcp('.box-content[id=' + clickedRef + ']');
		$hmcp('.box-content[step=second]').hide();
		$hmcp('.box-content[step=third]').hide();
		$hmcp(newStep).appendTo('#second-container');
		$hmcp(newStep).fadeIn(700);
		$hmcp('.arrow-right-button').unbind('click');
		
		if (clickedRef == 'personal') {
			$hmcp('.box-content[step=second] > ul > li > span').addClass('selected');
			$hmcp('.box-content[step=second] > ul > li').addClass('selected');
			var transportLink = $hmcp('#personalTask').attr('link');
			$hmcp('.arrow-right-button' ).attr('href', transportLink).show();
			$hmcp('.arrow-right-button').click(goBtn_CLICK);
			showGoBtn = true;
		}
	}
	
	if (currentStep == 'second') {
		$hmcp('.box-content[step=second] > ul > li > span').removeClass('selected');
		$hmcp('.box-content[step=second] > ul > li').removeClass('selected');
		$hmcp('.box-content[step=third] > ul > li > span').removeClass('selected');
		$hmcp('.box-content[step=third] > ul > li').removeClass('selected');

		var newStep = $hmcp('.box-content[id=' + clickedRef + ']');
		$hmcp('.box-content[step=third]').hide();
		$hmcp(newStep).appendTo('#third-container');
		$hmcp(newStep).fadeIn(700);
		$hmcp('.arrow-right-button').unbind('click');
	}
	
	if (currentStep == 'third') {
		$hmcp('.box-content[step=third] > ul > li').removeClass('selected');
		$hmcp('.box-content[step=third] > ul > li > span').removeClass('selected');
		hmcpLink = $hmcp(this).attr('link');
		$hmcp('.arrow-right-button').click(goBtn_CLICK);
	}
	
	if( currentStep == 'third' || newStep.html() == null)
		$hmcp( $go_button_location ).attr( 'href', $hmcp(this).attr('link') ).show();
	else if (showGoBtn == false) {
		$hmcp( $go_button_location ).hide();
	} 

		
	$hmcp(this).addClass('selected');
	$hmcp(this).children('.solid-plus-right-button').addClass('selected');
	gem_round_solid_plus_right_button_corners(); /* Needed for IE7 and IE8 */
}

function goBtn_CLICK(e) {
	window.location.href= $hmcp( $go_button_location ).attr( 'href');
}
