// JavaScript Document
$(document).ready(function(){
	var baseURL = window.location.host;
	
	var url_1 = 'catalogues_landing.html';
	var url_2 = 'http://www.google.com';
	var url_3 = 'http://www.behroozkaviani.com';
	
	var pw_1 = 'Paramount#';
	var pw_2 = 'google';
	var pw_3 = 'behrooz';
	
	$isIE6 = false;
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		$isIE6 = true;
	}
	
	$('#myiFrameDynamic').load(function(){
		var iFrameURL = '';
		try{
			iFrameURL = window.frames['myiFrameDynamic'].window.location.href;
		}catch(error){
			//alert('Caught exception while checking loaded URL!');
			iFrameURL = null;
		}
		
		if (iFrameURL) {
			//alert('got local URL: ' + iFrameURL);
			var iframeHeight = $(this).contents().find('body').height();
			var iframeHeightPadded = iframeHeight + 3;
			$(this).height(iframeHeightPadded);
			
			var submit = $(this).contents().find("#passwordBtn");  //id of the button in the iframe 
			var pwTxt = $(this).contents().find("#passwordTxt");  //id of the password text in the iframe
			submit.click(function(){ 
				//alert('[button pressed] got pwTxt = ' + pwTxt.val());
				passwordCheck(pwTxt.val());
			});
			
			pwTxt.keydown(function(event){
				//alert('got keydown event!!');
				if ((event.keyCode || event.which) == 13) {
					//alert('[enter pressed] got pwTxt = ' + pwTxt.val());
					passwordCheck(pwTxt.val());				
				}
			});
			
			function passwordCheck(pw){
				if (pw == pw_1) {
					return loadURL(url_1);
				} else if (pw == pw_2) {
					return loadURL(url_2);
				} else if (pw == pw_3) {
					return loadURL(url_3);
				}
			}
			
			function loadURL(url){
				window.frames['myiFrameDynamic'].window.location = url;
			}
		} else {
			//alert('not a local URL...');
			$(this).height(600);
		}
		
		//alert(window.frames['myiFrameDynamic'].window.location);
	});
});
