// google analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-17239608-1']);
_gaq.push(['_setDomainName', '.waplestore.com']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

// browser check
var appName = navigator.appName;
var userAgent = navigator.userAgent;
if (appName == "Microsoft Internet Explorer") {
	if(userAgent.indexOf("MSIE 6") > 0) {
		alert("This site is not compatible with Internet Explorer 6.");	
	}
}

window.addEventListener('load', function(){	
	var browser = navigator.userAgent.toLowerCase();

 	if (browser.indexOf('iphone') != -1 || browser.indexOf('ipod') != -1) { 
		setTimeout(function() { window.scrollTo(0, 1) }, 100)
	}

}, false);
	
function onClickFirstPage() {
	document.getElementById('screenshot_paging').innerHTML = '<ul class="screenshot_paging"><li><a href="#prev" class="prev_off" onfocus="blur()" >prev</a></li><li><a href="#1" class="page_on" onfocus="blur()" id="first_page">1</a></li><li><a href="#2" class="page_off" onfocus="blur()" id="second_page" onclick="onClickSecondPage()">2</a></li><li><a href="#next" class="next_on" onfocus="blur()" onclick="onClickSecondPage()">next</a></li></ul>';
	
	$('#screenshot_group1').animate({
		opacity:1,
		left: '+=706'
	}, 500, function() {
    // Animation complete.    
	});
	$('#screenshot_group2').animate({
		left: '+=706'
	}, 500, function() {
    // Animation complete.    
	});
}

function onClickSecondPage() {
	document.getElementById('screenshot_paging').innerHTML = '<ul class="screenshot_paging"><li><a href="#prev" class="prev_on" onfocus="blur()" onclick="onClickFirstPage()">prev</a></li><li><a href="#1" class="page_off" onfocus="blur()" id="first_page" onclick="onClickFirstPage()">1</a></li><li><a href="#2" class="page_on" onfocus="blur()" id="second_page">2</a></li><li><a href="#next" class="next_off" onfocus="blur()">next</a></li></ul>';

	$('#screenshot_group1').animate({
		opacity:0,
		left: '-=706'
	}, 500, function() {
  	// Animation complete.
	});
	$('#screenshot_group2').animate({
		left: '-=706' 
	}, 500, function() {
    // Animation complete.
	});
};

function setMainBG() {		
    var yoMainBG = document.getElementById("top_bg");		
	yoMainBG.style.top = "0px";
	yoMainBG.style.left = "235px";
}

function getBounds(tag) {
    var ret = new Object();
    if(document.all) {
        var rect = tag.getBoundingClientRect();
        ret.left = rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft);
        ret.top = rect.top + (document.documentElement.scrollTop || document.body.scrollTop);
        ret.width = rect.right - rect.left;
        ret.height = rect.bottom - rect.top;
    } else {
        var box = document.getBoxObjectFor(tag);
        ret.left = box.x;
        ret.top = box.y;
        ret.width = box.width;
        ret.height = box.height;
    }
    return ret;
}			    	

function setTWTRWidget() {
	new TWTR.Widget({
  		version: 2,
		type: 'profile',
  		rpp: 5,
  		interval: 3500,
  		width: 250,
  		height: 505,
  		theme: {
    	shell: {
      		background: '#ffffff',
      		color: '#000000'
    	},
    	tweets: {
      		background: '#ffffff',
      		color: '#000000',
      		links: '#e93657'
    	}
  	},
  	features: {
    	scrollbar: false,
    	loop: false,
    	live: true,
    	hashtags: true,
    	timestamp: true,
    	avatars: false,
    	behavior: 'all'
  	}
	}).render().setUser('waplestore').start();
	document.getElementById("twtr-widget-1").style.top = "10px";
	document.getElementById("twtr-widget-1").style.display = "none";
}

function toggleTwitter() {
	if (document.getElementById("twitterWrapper").style.display == "block") {
		document.getElementById("twitterWrapper").style.display = "none";
		document.getElementById("twtr-widget-1").style.display = "none";
		
		document.getElementById("twitterNavi").src = "http://waplestore.com/images/navi_twitter.png"
	} else {	
		document.getElementById("twitterNavi").src = "http://waplestore.com/images/navi_twitter_on.png"		
    	if(document.all) {			// IE일 경우 
			var objTop = document.getElementById("twitter").offsetTop;
			var objLeft = document.getElementById("twitter").offsetLeft;
				
			var twitterWrapper = document.getElementById("twitterWrapper");
			var twitterWidget = document.getElementById("twtr-widget-1");
			
			twitterWrapper.style.top = objTop + 23 + "px";
			twitterWrapper.style.left = objLeft - 174 + "px";
			twitterWrapper.style.position = "absolute";
			twitterWrapper.style.display = "block";
			
			twitterWidget.style.top =  0 + "px";
			twitterWidget.style.left = 0 + "px";
			twitterWidget.style.position = "relative";
			twitterWidget.style.display = "block";
    	} else {
    		var objTop = document.getElementById("twitter").offsetTop;
			var objLeft = document.getElementById("twitter").offsetLeft + document.getElementById('twitter').offsetWidth;
			
			var twitterWrapper = document.getElementById("twitterWrapper");
			var twitterWidget = document.getElementById("twtr-widget-1");
			
			twitterWrapper.style.top = objTop + 22 + "px";
			twitterWrapper.style.left = objLeft - 262 + "px";
			twitterWrapper.style.position = "absolute";
			twitterWrapper.style.display = "block";
			
			twitterWidget.style.top =  0 + "px";
			twitterWidget.style.left = 0 + "px";
			twitterWidget.style.position = "relative";
			twitterWidget.style.display = "block";	
    	}			
	}
}


var setMobileNotice = function() {
	var browser = navigator.userAgent.toLowerCase();
	var mobile_notice = $('#mobile_notice');
	
	var userAgent = navigator.userAgent.toLocaleLowerCase();
	if (userAgent.indexOf('iphone') != -1 || userAgent.indexOf('ipod') != -1) { 
		var mobile_notice = $('#mobile_notice');
		var mobile_notice_top = $(window).height() - 129;

		mobile_notice.css('top', $(window).height() );
		$(document).ready(function(){
			mobile_notice.animate( { "top": $(document).scrollTop() + mobile_notice_top +"px" }, 500 ); 
		
			if ($.cookie("mobile_notice_visible") != "true") {
				$(window).scroll(function(){
					mobile_notice.stop();
					mobile_notice.animate( { "top": $(document).scrollTop() + mobile_notice_top + "px" }, 1000 );
				});
			} else {
				mobile_notice.hide();
			}
		});
		
		$('#mobile_notice_close').css("cursor","pointer");
		$('#mobile_notice_close').click(function() {
			$('#mobile_notice_close').hide();
			$.cookie("mobile_notice_visible", "true");
		});
		
		$(document).oneTime(5000, function() {
			mobile_notice.animate({ top: $(document).scrollTop() + mobile_notice_top + mobile_notice_top + "px"}, 1000, function() { mobile_notice.hide(); });
			$.cookie("mobile_notice_visible", "true");
		});
	} else {
		mobile_notice.css("display","none");
	}
}
