irise.namespace("irise"); // sets the namespace
var iOSNavBtnInstanceArr = new Array(); 

irise.iOSBackNextButton = function(){
}

irise.iOSBackNextButton.prototype.onload = function(){
	
	var iOSNavBtnFullId = this.getId();
	var iOSNavBtnId = iOSNavBtnFullId.substring(iOSNavBtnFullId.length-4);// store the shortened instance id to be used as array element key
	
	iOSNavBtnInstanceArr[iOSNavBtnId] = this;
	
	//catch the attibutes from studio
	var widgetWidth = this.getProperty('width');
	var widgetHeight = this.getProperty('height');
	
	var iOSNavBtnLabelText = this.getProperty('iOSNavBtnLabel');
	if(iOSNavBtnLabelText == "" || iOSNavBtnLabelText == null || iOSNavBtnLabelText == "undefined")
		iOSNavBtnLabelText = "Back";
	
	var iOSNavBtnType = this.getProperty('iOSNavBtnType');
	if(iOSNavBtnType == "" || iOSNavBtnType == null || iOSNavBtnType == "undefined")
		iOSNavBtnType = "Back";
	
	var iOSNavBtnColor = this.getProperty('iOSNavBtnColor');
	if(iOSNavBtnColor == "" || iOSNavBtnColor == null || iOSNavBtnColor == "undefined")
		iOSNavBtnColor = "#000000";
	
	var settingsRight = {
		tl: {radius: 0},
		tr: {radius: 5},
		bl: {radius: 0},
		br: {radius: 5},
		
		antiAlias: true
	}
	
	var settingsLeft = {
		tl: {radius: 5},
		tr: {radius: 0},
		bl: {radius: 5},
		br: {radius: 0},
		
		antiAlias: true
	}
		
	if (iOSNavBtnType == "Back"){
		var iOSNavBtnCustonColorDiv = '<div class="iOSNavBtnCustomContainer"><div class="iOSNavBtnArrowLeft"></div><div class="iOSNavBtnMiddleCustom"><div class="iOSNavBtnLabelText" style="color:'+iOSNavBtnColor+'">'+iOSNavBtnLabelText+'</div></div><div class="iOSNavBtnRightCustom"></div></div>'
		
		var iOSNavBtnOverlayDiv = '<div class="iOSNavBtnOverlayContainer"><div class="iOSNavBtnArrowLeftOverlay"></div><div class="iOSNavBtnMiddleOverlay"><div class="iOSNavBtnLabelText">'+iOSNavBtnLabelText+'</div></div><div class="iOSNavBtnRightOverlay"></div></div>'
	}
	else if (iOSNavBtnType == "Next"){
		var iOSNavBtnCustonColorDiv = '<div class="iOSNavBtnCustomContainer"><div class="iOSNavBtnLeftCustom"></div><div class="iOSNavBtnMiddleCustom"><div class="iOSNavBtnLabelText" style="color:'+iOSNavBtnColor+'">'+iOSNavBtnLabelText+'</div></div><div class="iOSNavBtnArrowRight"></div></div>'
		
	var iOSNavBtnOverlayDiv = '<div class="iOSNavBtnOverlayContainer"><div class="iOSNavBtnLeftOverlay"></div><div class="iOSNavBtnMiddleOverlay"><div class="iOSNavBtnLabelText">'+iOSNavBtnLabelText+'</div></div><div class="iOSNavBtnArrowRightOverlay"></div></div>'
	}
	else if (iOSNavBtnType == "Gradient Button"){
		var iOSNavBtnCustonColorDiv = '<div class="iOSNavBtnCustomContainer"><div class="iOSNavBtnLeftCustom"></div><div class="iOSNavBtnMiddleCustom"><div class="iOSNavBtnLabelText" style="color:'+iOSNavBtnColor+'">'+iOSNavBtnLabelText+'</div></div><div class="iOSNavBtnRightCustom"></div></div>'
		
		var iOSNavBtnOverlayDiv = '<div class="iOSNavBtnOverlayContainer"><div class="iOSNavBtnLeftOverlay"></div><div class="iOSNavBtnMiddleOverlay"><div class="iOSNavBtnLabelText">'+iOSNavBtnLabelText+'</div></div><div class="iOSNavBtnRightOverlay"></div></div>'	
	}
	else if (iOSNavBtnType == "Button"){
		var iOSNavBtnCustonColorDiv = '<div class="iOSNavBtnCustomContainer"><div class="iOSNavBtnLeftCustom"></div><div class="iOSNavBtnMiddleCustom"><div class="iOSNavBtnLabelText" style="color:#FFFFFF">'+iOSNavBtnLabelText+'</div></div><div class="iOSNavBtnRightCustom"></div></div>'
		
		var iOSNavBtnOverlayDiv='';
	}
	
	var toAppendDiv ='<div class="iOSNavBtnOuterContainer">'+iOSNavBtnCustonColorDiv+iOSNavBtnOverlayDiv+'</div>';
		
	this.getWidgetDiv().append(toAppendDiv);
	if (iOSNavBtnType == "Back"){
		$('#'+iOSNavBtnFullId+' .iOSNavBtnArrowLeft').css('border-right-color', iOSNavBtnColor);
		$('#'+iOSNavBtnFullId+' .iOSNavBtnMiddleCustom').css('background-color', iOSNavBtnColor);
		$('#'+iOSNavBtnFullId+' .iOSNavBtnRightCustom').css('background-color', iOSNavBtnColor);
		curvyCorners(settingsRight, '#'+iOSNavBtnFullId+' .iOSNavBtnRightCustom');
	}
	else if (iOSNavBtnType == "Next"){
		$('#'+iOSNavBtnFullId+' .iOSNavBtnArrowRight').css('border-left-color', iOSNavBtnColor);
		$('#'+iOSNavBtnFullId+' .iOSNavBtnMiddleCustom').css('background-color', iOSNavBtnColor);
		$('#'+iOSNavBtnFullId+' .iOSNavBtnLeftCustom').css('background-color', iOSNavBtnColor);
		curvyCorners(settingsLeft, '#'+iOSNavBtnFullId+' .iOSNavBtnLeftCustom');
	}
	else if (iOSNavBtnType == "Gradient Button"){
		$('#'+iOSNavBtnFullId+' .iOSNavBtnLeftCustom').css('background-color', iOSNavBtnColor);
		$('#'+iOSNavBtnFullId+' .iOSNavBtnMiddleCustom').css('background-color', iOSNavBtnColor);
		$('#'+iOSNavBtnFullId+' .iOSNavBtnRightCustom').css('background-color', iOSNavBtnColor);
		curvyCorners(settingsLeft, '#'+iOSNavBtnFullId+' .iOSNavBtnLeftCustom');
		curvyCorners(settingsRight, '#'+iOSNavBtnFullId+' .iOSNavBtnRightCustom');
	}
	else if (iOSNavBtnType == "Button"){
		$('#'+iOSNavBtnFullId+' .iOSNavBtnLeftCustom').css('background-color', iOSNavBtnColor);
		$('#'+iOSNavBtnFullId+' .iOSNavBtnMiddleCustom').css('background-color', iOSNavBtnColor);
		$('#'+iOSNavBtnFullId+' .iOSNavBtnRightCustom').css('background-color', iOSNavBtnColor);
		curvyCorners(settingsLeft, '#'+iOSNavBtnFullId+' .iOSNavBtnLeftCustom');
		curvyCorners(settingsRight, '#'+iOSNavBtnFullId+' .iOSNavBtnRightCustom');
	}
	
	// correct the offsets appearing for the widget Div
	this.getWidgetDiv().css('lineHeight', 0);
	if($.browser.msie){// for IE
		this.getWidgetDiv().css('marginTop', 0);
		if ($.browser.version < 8)
			$('#'+iOSNavBtnFullId+' .iOSNavBtnLabelText').css('margin-top', '16px');
		else{
			$('#'+iOSNavBtnFullId+' .iOSNavBtnLabelText').css('margin-top', '15px');
			this.getWidgetDiv().css('marginLeft', 1);
		}
			
	}
	else if($.browser.opera){ // for Opera
		this.getWidgetDiv().css('marginTop', 0);
		$('#'+iOSNavBtnFullId+' .iOSNavBtnLabelText').css('margin-top', '21px');
	}
	else if($.browser.safari){// for Safari
		if((parseInt($.browser.version))>=534)
			this.getWidgetDiv().css('marginTop', 0);
		else{
			this.getWidgetDiv().css('marginTop', -5);
		}
	}

	if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) // Chrome
		this.getWidgetDiv().css('marginTop', 0);
		
	var iOSNavBarMiddleWidth = $('#'+iOSNavBtnFullId+' .iOSNavBtnLabelText').css('width');

	if (iOSNavBarMiddleWidth == '0px'){
		if (this.getWidgetDiv().css('display') == 'block'){
			this.getWidgetDiv().parent().css('display', 'block');
			var iOSNavBarMiddleWidth = $('#'+iOSNavBtnFullId+' .iOSNavBtnLabelText').css('width');
			this.getWidgetDiv().parent().css('display', 'none');
		}
		else if (this.getWidgetDiv().css('display') == 'none'){
			this.getWidgetDiv().css('display', 'block');
			var iOSNavBarMiddleWidth = $('#'+iOSNavBtnFullId+' .iOSNavBtnLabelText').css('width');
			this.getWidgetDiv().css('display', 'none');
		}
	}
	
	if (iOSNavBtnType == "Back" || iOSNavBtnType == "Next"){
		if($.browser.msie)
			this.getWidgetDiv().width(parseInt(iOSNavBarMiddleWidth)+21);
		else
			this.getWidgetDiv().width(parseInt(iOSNavBarMiddleWidth)+20);
	}
	else if (iOSNavBtnType == "Gradient Button" || iOSNavBtnType == "Button"){
		if($.browser.msie)
			this.getWidgetDiv().width(parseInt(iOSNavBarMiddleWidth)+15);
		else
			this.getWidgetDiv().width(parseInt(iOSNavBarMiddleWidth)+14);
	}
			
	$('#'+iOSNavBtnFullId+' .iOSNavBtnOuterContainer').bind('mouseup', function(e) {
		iOSNavBtnInstanceArr[iOSNavBtnId].sendEvent('OnClick');		
	});
	
}//onload ends
